| 285 | // Works for: vector, deque, list, set, queue, circular buffers, etc. |
| 286 | template<typename Container> |
| 287 | void test_container_move_semantics() { |
| 288 | auto ptr = make_shared_int(42); |
| 289 | |
| 290 | Container source; |
| 291 | populate(source, ptr); |
| 292 | |
| 293 | FL_REQUIRE(ptr.use_count() == 2); // 1 in container, 1 local |
| 294 | FL_REQUIRE(source.size() == 1); |
| 295 | |
| 296 | Container destination; |
| 297 | destination = fl::move(source); |
| 298 | |
| 299 | FL_CHECK(source.size() == 0); |
| 300 | FL_CHECK(source.empty()); |
| 301 | FL_CHECK(destination.size() == 1); |
| 302 | |
| 303 | // Retrieve and check value, but let it go out of scope immediately |
| 304 | { |
| 305 | auto retrieved = retrieve(destination); |
| 306 | FL_CHECK(*retrieved == 42); |
| 307 | } |
| 308 | FL_CHECK(ptr.use_count() == 2); // Proves move, not copy |
| 309 | |
| 310 | destination.clear(); |
| 311 | FL_CHECK(ptr.use_count() == 1); // Only local reference remains |
| 312 | } |
| 313 | |
| 314 | // Test map container move semantics with key-value pairs |
| 315 | // Works for: map, unordered_map, SortedHeapMap, unsorted_map_fixed, HashMapLru |