MCPcopy Create free account
hub / github.com/FastLED/FastLED / test_container_move_semantics

Function test_container_move_semantics

tests/test_container_helpers.h:287–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285// Works for: vector, deque, list, set, queue, circular buffers, etc.
286template<typename Container>
287void 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

Callers

nothing calls this directly

Calls 7

make_shared_intFunction · 0.85
populateFunction · 0.85
retrieveFunction · 0.85
use_countMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected