libstdc++: Make __gnu_debug::vector usable in constant expressions [PR109536]
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / capacity / constexpr.cc
blobc331dbd5e5714039b49015a36e6c96403ea62b6c
1 // { dg-do compile { target c++20 } }
3 #include <vector>
4 #include <testsuite_hooks.h>
6 constexpr bool
7 test_empty()
9 std::vector<int> v;
10 VERIFY( v.empty() );
11 v = {1};
12 VERIFY( !v.empty() );
14 return true;
17 static_assert( test_empty() );
19 constexpr bool
20 test_size()
22 std::vector<int> v;
23 VERIFY( v.size() == 0 );
24 v = {1};
25 VERIFY( v.size() == 1 );
27 VERIFY( v.max_size() != 0 );
29 return true;
32 static_assert( test_size() );
34 constexpr bool
35 test_capacity()
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() );
44 return true;
47 static_assert( test_capacity() );
49 constexpr bool
50 test_resize()
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 );
63 return true;
66 static_assert( test_resize() );
68 constexpr bool
69 test_reserve()
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 );
79 return true;
82 static_assert( test_reserve() );
84 constexpr bool
85 test_shrink_to_fit()
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
104 return true;
107 static_assert( test_shrink_to_fit() );