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=(const reference&)
12
13#include <cassert>
14#include <vector>
15#include <utility>
16
17#include "test_macros.h"
18
19TEST_CONSTEXPR_CXX20 bool test() {
20 std::vector<bool> vec;
21 typedef std::vector<bool>::reference Ref;
22 vec.push_back(true);
23 vec.push_back(false);
24 Ref ref1 = vec[0];
25 Ref ref2 = vec[1];
26 ref2 = ref1;
27 // Ref&
28 {
29 vec[0] = false;
30 vec[1] = true;
31 ref1 = ref2;
32 assert(vec[0]);
33 assert(vec[1]);
34 }
35 {
36 vec[0] = true;
37 vec[1] = false;
38 ref1 = ref2;
39 assert(!vec[0]);
40 assert(!vec[1]);
41 }
42 // Ref&&
43 {
44 vec[0] = false;
45 vec[1] = true;
46 ref1 = std::move(ref2);
47 assert(vec[0]);
48 assert(vec[1]);
49 }
50 {
51 vec[0] = true;
52 vec[1] = false;
53 ref1 = std::move(ref2);
54 assert(!vec[0]);
55 assert(!vec[1]);
56 }
57 // const Ref&
58 {
59 vec[0] = false;
60 vec[1] = true;
61 ref1 = static_cast<const Ref&>(ref2);
62 assert(vec[0]);
63 assert(vec[1]);
64 }
65 {
66 vec[0] = true;
67 vec[1] = false;
68 ref1 = static_cast<const Ref&>(ref2);
69 assert(!vec[0]);
70 assert(!vec[1]);
71 }
72 return true;
73}
74
75int main(int, char**) {
76 test();
77#if TEST_STD_VER > 17
78 static_assert(test());
79#endif
80
81 return 0;
82}
83

source code of libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp