| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
|
| 3 |
#include <memory> |
| 4 |
#include <testsuite_hooks.h> |
| 5 |
|
| 6 |
constexpr bool |
| 7 |
test_swap_single() |
| 8 |
{ |
| 9 |
std::unique_ptr<int> p1; |
| 10 |
swap(p1, p1); |
| 11 |
VERIFY( !p1 ); |
| 12 |
std::unique_ptr<int> p2; |
| 13 |
swap(p1, p2); |
| 14 |
VERIFY( !p1 && !p2 ); |
| 15 |
std::unique_ptr<int> p3(new int(3)); |
| 16 |
swap(p3, p3); |
| 17 |
VERIFY( *p3 == 3 ); |
| 18 |
swap(p1, p3); |
| 19 |
VERIFY( *p1 == 3 ); |
| 20 |
std::unique_ptr<int> p4(new int(4)); |
| 21 |
swap(p4, p1); |
| 22 |
VERIFY( *p4 == 3 ); |
| 23 |
VERIFY( *p1 == 4 ); |
| 24 |
|
| 25 |
return true; |
| 26 |
} |
| 27 |
static_assert( test_swap_single() ); |
| 28 |
|
| 29 |
constexpr bool |
| 30 |
test_swap_array() |
| 31 |
{ |
| 32 |
std::unique_ptr<int[]> a1; |
| 33 |
std::unique_ptr<int[]> a2; |
| 34 |
swap(a1, a2); |
| 35 |
VERIFY( !a1 && !a2 ); |
| 36 |
std::unique_ptr<int[]> a3(new int[]{3}); |
| 37 |
swap(a1, a3); |
| 38 |
VERIFY( a1[0] == 3 ); |
| 39 |
std::unique_ptr<int[]> a4(new int[]{4, 5}); |
| 40 |
swap(a1, a4); |
| 41 |
VERIFY( a1[1] == 5 ); |
| 42 |
|
| 43 |
return true; |
| 44 |
} |
| 45 |
static_assert( test_swap_array() ); |