| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
#include <testsuite_hooks.h> |
| 5 |
|
| 6 |
constexpr bool |
| 7 |
test_empty() |
| 8 |
{ |
| 9 |
std::vector<int> v; |
| 10 |
VERIFY( v.empty() ); |
| 11 |
v = {1}; |
| 12 |
VERIFY( !v.empty() ); |
| 13 |
|
| 14 |
return true; |
| 15 |
} |
| 16 |
|
| 17 |
static_assert( test_empty() ); |
| 18 |
|
| 19 |
constexpr bool |
| 20 |
test_size() |
| 21 |
{ |
| 22 |
std::vector<int> v; |
| 23 |
VERIFY( v.size() == 0 ); |
| 24 |
v = {1}; |
| 25 |
VERIFY( v.size() == 1 ); |
| 26 |
|
| 27 |
VERIFY( v.max_size() != 0 ); |
| 28 |
|
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
static_assert( test_size() ); |
| 33 |
|
| 34 |
constexpr bool |
| 35 |
test_capacity() |
| 36 |
{ |
| 37 |
std::vector<int> v; |
| 38 |
VERIFY( v.size() == 0 ); |
| 39 |
VERIFY( v.capacity() == v.size() ); |
| 40 |
v = {1, 2, 3}; |
| 41 |
VERIFY( v.size() == 3 ); |
| 42 |
VERIFY( v.capacity() == v.size() ); |
| 43 |
|
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
static_assert( test_capacity() ); |
| 48 |
|
| 49 |
constexpr bool |
| 50 |
test_resize() |
| 51 |
{ |
| 52 |
std::vector<int> v; |
| 53 |
v.reserve(9); |
| 54 |
VERIFY( v.size() == 0 ); |
| 55 |
VERIFY( v.capacity() == 9 ); |
| 56 |
v.resize(5); |
| 57 |
VERIFY( v.size() == 5 ); |
| 58 |
VERIFY( v.capacity() == 9 ); |
| 59 |
v.resize(15, 6); |
| 60 |
VERIFY( v.size() == 15 ); |
| 61 |
VERIFY( v[10] == 6 ); |
| 62 |
|
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
static_assert( test_resize() ); |
| 67 |
|
| 68 |
constexpr bool |
| 69 |
test_reserve() |
| 70 |
{ |
| 71 |
std::vector<int> v; |
| 72 |
v.reserve(9); |
| 73 |
VERIFY( v.size() == 0 ); |
| 74 |
VERIFY( v.capacity() == 9 ); |
| 75 |
v.resize(2); |
| 76 |
VERIFY( v.size() == 2 ); |
| 77 |
VERIFY( v.capacity() == 9 ); |
| 78 |
|
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
static_assert( test_reserve() ); |
| 83 |
|
| 84 |
constexpr bool |
| 85 |
test_shrink_to_fit() |
| 86 |
{ |
| 87 |
std::vector<int> v; |
| 88 |
v.reserve(9); |
| 89 |
v.shrink_to_fit(); |
| 90 |
#if __cpp_exceptions |
| 91 |
VERIFY( v.capacity() == 0 ); |
| 92 |
#else |
| 93 |
VERIFY( v.capacity() == 9 ); |
| 94 |
#endif |
| 95 |
v.reserve(9); |
| 96 |
v.resize(5); |
| 97 |
v.shrink_to_fit(); |
| 98 |
#if __cpp_exceptions |
| 99 |
VERIFY( v.capacity() == v.size() ); |
| 100 |
#else |
| 101 |
VERIFY( v.capacity() == 9 ); |
| 102 |
#endif |
| 103 |
|
| 104 |
return true; |
| 105 |
} |
| 106 |
|
| 107 |
static_assert( test_shrink_to_fit() ); |