1 // { dg-do compile { target c++20 } }
4 #include <testsuite_hooks.h>
10 VERIFY( v
.begin() == v
.end() );
12 VERIFY( v
.begin() == v
.end() );
14 VERIFY( v
.begin() != v
.end() );
15 VERIFY( v
.cbegin() == v
.begin() );
16 VERIFY( v
.crbegin() == v
.rbegin() );
17 VERIFY( v
.cend() == v
.end() );
18 VERIFY( v
.crend() == v
.rend() );
22 VERIFY( &*it
== &v
.front() );
23 VERIFY( &it
[1] == &v
[1] );
24 VERIFY( it
++ == v
.begin() );
25 VERIFY( ++it
== v
.end() );
26 VERIFY( (it
- 2) == v
.begin() );
27 VERIFY( (it
- v
.begin()) == 2 );
30 VERIFY( (it
+ 1) == v
.end() );
31 VERIFY( (1 + it
) == v
.end() );
35 VERIFY( it
== v
.begin() );
36 VERIFY( it2
== v
.end() );
38 auto rit
= v
.rbegin();
39 VERIFY( rit
[0] == 0 );
40 VERIFY( &*rit
== &v
.back() );
41 VERIFY( &rit
[1] == &v
[0] );
42 VERIFY( rit
++ == v
.rbegin() );
43 VERIFY( ++rit
== v
.rend() );
44 VERIFY( (rit
- 2) == v
.rbegin() );
45 VERIFY( (rit
- v
.rbegin()) == 2 );
48 VERIFY( (rit
+ 1) == v
.rend() );
49 VERIFY( (1 + rit
) == v
.rend() );
51 auto rit2
= v
.rbegin();
53 VERIFY( rit
== v
.rbegin() );
54 VERIFY( rit2
== v
.rend() );
59 static_assert(test_iterators());
64 std::vector
<int> v
{1, 2, 3};
65 VERIFY( v
.at(1) == 2 );
67 VERIFY( &v
[2] == &v
.at(2) );
68 VERIFY( &v
.front() == &v
[0] );
69 VERIFY( &v
.back() == &v
[2] );
72 VERIFY( vc
.at(1) == 2 );
73 VERIFY( &vc
.at(1) == &v
.at(1) );
74 VERIFY( &vc
.at(1) == &vc
[1] );
75 VERIFY( &vc
.front() == &vc
[0] );
76 VERIFY( &vc
.back() == &vc
[2] );
81 static_assert(test_access());
83 template<typename T
= int>
84 constexpr std::false_type
85 access_empty() { return {}; }
87 template<typename T
= int>
88 requires (std::bool_constant
<&std::vector
<T
>().at(0) != nullptr>::value
)
89 constexpr std::true_type
90 access_empty() { return {}; }
92 template<typename T
= int>
93 requires (std::bool_constant
<&std::vector
<T
>()[0] != nullptr>::value
)
94 constexpr std::true_type
95 access_empty() { return {}; }
97 template<typename T
= int>
98 requires (std::bool_constant
<&std::vector
<T
>().front() != nullptr>::value
)
99 constexpr std::true_type
100 access_empty() { return {}; }
102 template<typename T
= int>
103 requires (std::bool_constant
<&std::vector
<T
>().back() != nullptr>::value
)
104 constexpr std::true_type
105 access_empty() { return {}; }
107 static_assert( ! access_empty() );
109 template<typename T
= int>
110 constexpr std::false_type
111 access_past_the_end() { return {}; }
113 template<typename T
= int>
114 requires (std::bool_constant
<&std::vector
<T
>(3).at(3) != nullptr>::value
)
115 constexpr std::true_type
116 access_past_the_end() { return {}; }
118 template<typename T
= int>
119 requires (std::bool_constant
<&std::vector
<T
>(3)[3] != nullptr>::value
)
120 constexpr std::true_type
121 access_past_the_end() { return {}; }
123 static_assert( ! access_past_the_end() );