Debian Codegraph @

libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <vector>
10
11 // reference& operator=(bool)
12
13 #include <cassert>
14 #include <vector>
15
16 #include "test_macros.h"
17
18 TEST_CONSTEXPR_CXX20 bool test() {
19 std::vector<bool> vec;
20 typedef std::vector<bool>::reference Ref;
21 vec.push_back(true);
22 vec.push_back(false);
23 Ref ref = vec[0];
24 const Ref cref = vec[0];
25
26 assert(ref);
27 ref = false;
28 assert(!vec[0]);
29 assert(!vec[1]);
30 ref = true;
31 assert(vec[0]);
32 assert(!vec[1]);
33
34 assert(cref);
35
36 #if TEST_STD_VER > 20
37 cref = false;
38 assert(!vec[0]);
39 assert(!vec[1]);
40 cref = true;
41 assert(vec[0]);
42 assert(!vec[1]);
43 #endif
44
45 return true;
46 }
47
48 int main(int, char**) {
49 test();
50 #if TEST_STD_VER > 17
51 static_assert(test());
52 #endif
53
54 return 0;
55 }