Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Spy {
- explicit Spy(bool& is_deleted, int& copy_count)
- : is_deleted_(is_deleted), copy_count_(copy_count) {}
- Spy(const Spy& rhs)
- : is_deleted_(rhs.is_deleted_), copy_count_(rhs.copy_count_) {
- ++copy_count_;
- }
- ~Spy() {
- is_deleted_ = true;
- }
- bool& is_deleted_;
- int& copy_count_;
- };
- void MoveConstructorOrGet() {
- {
- UniquePtr<Spy> uptr(nullptr);
- UniquePtr<Spy> uptr2(std::move(uptr));
- ASSERT_EQUAL(uptr.Get(), nullptr);
- ASSERT_EQUAL(uptr2.Get(), nullptr);
- } {
- int copy_count_ = 0;
- bool is_deleted = false;
- auto *ptr = new Spy(is_deleted, copy_count_);
- UniquePtr<Spy> uptr(ptr);
- UniquePtr<Spy> uptr2(std::move(uptr));
- ASSERT_EQUAL(uptr.Get(), nullptr);
- ASSERT_EQUAL(uptr2.Get(), ptr)
- ASSERT_EQUAL(copy_count_, 0)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement