Fortran: fix bogus diagnostics on renamed interface import [PR110993]
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / bool / capacity / constexpr.cc
blob534128c487e435483abe0a8751e91043c75ebce7
1 // { dg-do compile { target c++20 } }
3 #include <vector>
4 #include <testsuite_hooks.h>
6 constexpr std::size_t
7 capacity_for(std::size_t n)
9 std::size_t N = std::vector<bool>(1).capacity();
10 if (auto r = n % N)
11 return n - r + N;
12 return n;
15 constexpr bool
16 test_empty()
18 std::vector<bool> v;
19 VERIFY( v.empty() );
20 v = {1};
21 VERIFY( !v.empty() );
23 return true;
26 static_assert( test_empty() );
28 constexpr bool
29 test_size()
31 std::vector<bool> v;
32 VERIFY( v.size() == 0 );
33 v = {1};
34 VERIFY( v.size() == 1 );
36 VERIFY( v.max_size() != 0 );
38 return true;
41 static_assert( test_size() );
43 constexpr bool
44 test_capacity()
46 std::vector<bool> v;
47 VERIFY( v.size() == 0 );
48 VERIFY( v.capacity() == v.size() );
49 v = {false, false, false};
50 VERIFY( v.size() == 3 );
51 VERIFY( v.capacity() >= v.size() );
53 return true;
56 static_assert( test_capacity() );
58 constexpr bool
59 test_resize()
61 std::vector<bool> v;
62 v.reserve(9);
63 VERIFY( v.size() == 0 );
64 VERIFY( v.capacity() == capacity_for(9) );
65 v.resize(5);
66 VERIFY( v.size() == 5 );
67 VERIFY( v.capacity() == capacity_for(9) );
68 v.resize(900, true);
69 VERIFY( v.size() == 900 );
70 VERIFY( v.capacity() == capacity_for(900) );
71 VERIFY( v[10] == true );
73 return true;
76 static_assert( test_resize() );
78 constexpr bool
79 test_reserve()
81 std::vector<bool> v;
82 v.reserve(9);
83 VERIFY( v.size() == 0 );
84 VERIFY( v.capacity() == capacity_for(9) );
85 v.resize(2);
86 VERIFY( v.size() == 2 );
87 VERIFY( v.capacity() == capacity_for(9) );
88 v.resize(300);
89 v.resize(100);
90 VERIFY( v.size() == 100 );
91 VERIFY( v.capacity() == capacity_for(300) );
93 return true;
96 static_assert( test_reserve() );
98 constexpr bool
99 test_shrink_to_fit()
101 std::vector<bool> v;
102 v.reserve(9);
103 v.shrink_to_fit();
104 VERIFY( v.capacity() == 0 );
105 v.reserve(9);
106 v.resize(5);
107 v.shrink_to_fit();
108 VERIFY( v.capacity() == capacity_for(v.size()) );
110 return true;
113 static_assert( test_shrink_to_fit() );