| 19 | #include "fl/stl/int.h" |
| 20 | |
| 21 | FL_TEST_FILE(FL_FILEPATH) { |
| 22 | |
| 23 | namespace { |
| 24 | |
| 25 | // Tracking allocator that records copy and move operations |
| 26 | template <typename T> |
| 27 | class TrackingAllocator { |
| 28 | public: |
| 29 | // Type definitions required by STL |
| 30 | using value_type = T; |
| 31 | using pointer = T*; |
| 32 | using const_pointer = const T*; |
| 33 | using reference = T&; |
| 34 | using const_reference = const T&; |
| 35 | using size_type = fl::size; |
| 36 | using difference_type = fl::ptrdiff_t; |
| 37 | |
| 38 | // Rebind allocator to type U |
| 39 | template <typename U> |
| 40 | struct rebind { |
| 41 | using other = TrackingAllocator<U>; |
| 42 | }; |
| 43 | |
| 44 | // Tracking state (shared pointer to allow copy/move tracking) |
| 45 | struct Stats { |
| 46 | int copy_constructs = 0; |
| 47 | int move_constructs = 0; |
| 48 | int copy_assigns = 0; |
| 49 | int move_assigns = 0; |
| 50 | int allocations = 0; |
| 51 | int deallocations = 0; |
| 52 | |
| 53 | void reset() { |
| 54 | copy_constructs = 0; |
| 55 | move_constructs = 0; |
| 56 | copy_assigns = 0; |
| 57 | move_assigns = 0; |
| 58 | allocations = 0; |
| 59 | deallocations = 0; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | Stats* stats; // Non-owning pointer to shared stats |
| 64 | |
| 65 | // Default constructor |
| 66 | TrackingAllocator() noexcept : stats(nullptr) {} |
| 67 | |
| 68 | // Constructor with stats tracking |
| 69 | explicit TrackingAllocator(Stats* s) noexcept : stats(s) {} |
| 70 | |
| 71 | // Copy constructor |
| 72 | TrackingAllocator(const TrackingAllocator& other) noexcept : stats(other.stats) { |
| 73 | if (stats) { |
| 74 | stats->copy_constructs++; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Move constructor |