xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/reference.swap.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 // vector<bool>
11 
12 // static void swap(reference x, reference y) noexcept;
13 
14 #include <vector>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 int main()
20 {
21 
22     bool a[] = {false, true, false, true};
23     bool* an = a + sizeof(a)/sizeof(a[0]);
24 
25     std::vector<bool> v(a, an);
26     std::vector<bool>::reference r1 = v[0];
27     std::vector<bool>::reference r2 = v[3];
28 
29 #if TEST_STD_VER >= 11
30     static_assert((noexcept(v.swap(r1,r2))), "");
31 #endif
32 
33     assert(!r1);
34     assert( r2);
35     v.swap(r1, r2);
36     assert( r1);
37     assert(!r2);
38 }
39