]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/bool/cmp_c++20.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / bool / cmp_c++20.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
bd2420f8
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++2a" }
1ae8edf5 19// { dg-do compile { target c++2a } }
a04b73e1 20// { dg-xfail-if "not supported" { debug_mode } }
bd2420f8
JW
21
22#include <vector>
23#include <testsuite_hooks.h>
24
1ae8edf5 25constexpr bool
bd2420f8
JW
26test01()
27{
28 std::vector<bool> c1{ 1, 0, 1 }, c2{ 1, 0, 1, 0 }, c3{ 1, 1, 1 };
29 VERIFY( c1 == c1 );
30 VERIFY( std::is_eq(c1 <=> c1) );
31 VERIFY( c1 < c2 );
32 VERIFY( std::is_lt(c1 <=> c2) );
33 VERIFY( c1 < c3 );
34 VERIFY( std::is_lt(c1 <=> c3) );
35 VERIFY( c2 < c3 );
36 VERIFY( std::is_lt(c2 <=> c3) );
37
38 static_assert( std::totally_ordered<std::vector<bool>> );
39
40 static_assert( std::three_way_comparable<std::vector<bool>,
41 std::strong_ordering> );
1ae8edf5
JW
42
43 return true;
bd2420f8
JW
44}
45
1ae8edf5 46constexpr bool
bd2420f8
JW
47test05()
48{
49 // vector<bool> iterators are random access, so should support <=>
50
51 std::vector<bool> c{ 1, 1, 1 };
52 VERIFY( c.begin() == c.cbegin() );
53 VERIFY( std::is_eq(c.begin() <=> c.cbegin()) );
54
55 VERIFY( c.begin() < c.end() );
56 VERIFY( std::is_lt(c.begin() <=> c.end()) );
57
58 VERIFY( c.begin() < c.cend() );
59 VERIFY( std::is_lt(c.begin() <=> c.cend()) );
60
61 VERIFY( c.crbegin() == c.rbegin() );
62 VERIFY( std::is_eq(c.crbegin() <=> c.rbegin()) );
63
64 VERIFY( c.rend() > c.rbegin() );
65 VERIFY( std::is_gt(c.rend() <=> c.rbegin()) );
66
67 static_assert( std::same_as<decltype(c.begin() <=> c.begin()),
68 std::strong_ordering> );
bd2420f8 69
1ae8edf5 70 return true;
bd2420f8 71}
1ae8edf5
JW
72
73static_assert( test01() );
74static_assert( test05() );