NOT* thread-safe
| 17 | |
| 18 | // *NOT* thread-safe |
| 19 | struct Foo |
| 20 | { |
| 21 | Foo() : copied(false) { id = _id()++; } |
| 22 | Foo(Foo const& other) : id(other.id), copied(true) { } |
| 23 | Foo(Foo&& other) : id(other.id), copied(other.copied) { other.copied = true; } |
| 24 | Foo& operator=(Foo&& other) |
| 25 | { |
| 26 | verify(); |
| 27 | id = other.id, copied = other.copied; |
| 28 | other.copied = true; |
| 29 | return *this; |
| 30 | } |
| 31 | ~Foo() { verify(); } |
| 32 | |
| 33 | private: |
| 34 | void verify() |
| 35 | { |
| 36 | if (copied) return; |
| 37 | if (id != _last_destroyed_id() + 1) { |
| 38 | _destroyed_in_order() = false; |
| 39 | } |
| 40 | _last_destroyed_id() = id; |
| 41 | ++_destroy_count(); |
| 42 | } |
| 43 | |
| 44 | public: |
| 45 | static void reset() { _destroy_count() = 0; _id() = 0; _destroyed_in_order() = true; _last_destroyed_id() = -1; } |
| 46 | static int destroy_count() { return _destroy_count(); } |
| 47 | static bool destroyed_in_order() { return _destroyed_in_order(); } |
| 48 | |
| 49 | private: |
| 50 | static int& _destroy_count() { static int c = 0; return c; } |
| 51 | static int& _id() { static int i = 0; return i; } |
| 52 | static bool& _destroyed_in_order() { static bool d = true; return d; } |
| 53 | static int& _last_destroyed_id() { static int i = -1; return i; } |
| 54 | |
| 55 | int id; |
| 56 | bool copied; |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | #if MOODYCAMEL_HAS_EMPLACE |
no outgoing calls