Advertisement
cepxuozab

RAII_SWAP

Jun 11th, 2024
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. void SwapTest() {
  2.         bool is_deleted = false;
  3.         bool is_deleted2 = false;
  4.         int copy_count_ = 0;
  5.         int copy_count_2 = 0;
  6.  
  7.         auto *ptr = new Spy(is_deleted, copy_count_);
  8.         auto *ptr2 = new Spy(is_deleted2, copy_count_2);
  9.  
  10.         UniquePtr<Spy> uptr(ptr);
  11.         UniquePtr<Spy> uptr2(ptr2);
  12.  
  13.         uptr.Swap(uptr2);
  14.  
  15.         ASSERT_EQUAL(uptr.Get(), ptr2);
  16.         ASSERT_EQUAL(uptr2.Get(), ptr);
  17.  
  18.        ASSERT_EQUAL(copy_count_, 0)
  19.         ASSERT_EQUAL(copy_count_2, 0)
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement