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