Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Counter {
- static size_t constructed;
- Counter() { ++constructed; }
- Counter(const Counter&) { ++constructed; }
- Counter(Counter&&) = default;
- Counter& operator=(const Counter&) { ++constructed; return *this; }
- Counter& operator=(Counter&&) = default;
- ~Counter() = default;
- size_t value = 0;
- };
- size_t Counter::constructed = 0;
- void Test(){
- Counter::constructed = 0;
- LazyValue<Counter> val([]() { return Counter(); });
- assert(Counter::constructed == 0u);
- assert(!val.HasValue());
- val.Get();
- assert(Counter::constructed == 1u);
- assert(val.HasValue());
- Counter counter = val.Get();
- assert(Counter::constructed == 2u);
- essert(counter.value == 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement