Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / template.bitset / bitset.members / flip_one.pass.cpp
blobadb8d05b5e7f5fad17c67eadb825a416edba910d
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 //===----------------------------------------------------------------------===//
9 // bitset<N>& flip(size_t pos); // constexpr since C++23
11 #include <bitset>
12 #include <cassert>
13 #include <cstddef>
14 #include <vector>
16 #include "../bitset_test_cases.h"
17 #include "test_macros.h"
19 template <std::size_t N>
20 TEST_CONSTEXPR_CXX23 void test_flip_one() {
21 std::vector<std::bitset<N> > const cases = get_test_cases<N>();
22 for (std::size_t c = 0; c != cases.size(); ++c) {
23 std::bitset<N> v = cases[c];
24 if (v.size() > 0) {
25 std::size_t middle = v.size() / 2;
26 v.flip(middle);
27 bool b = v[middle];
28 assert(v[middle] == b);
29 v.flip(middle);
30 assert(v[middle] != b);
31 v.flip(middle);
32 assert(v[middle] == b);
37 TEST_CONSTEXPR_CXX23 bool test() {
38 test_flip_one<0>();
39 test_flip_one<1>();
40 test_flip_one<31>();
41 test_flip_one<32>();
42 test_flip_one<33>();
43 test_flip_one<63>();
44 test_flip_one<64>();
45 test_flip_one<65>();
47 return true;
50 int main(int, char**) {
51 test();
52 test_flip_one<1000>(); // not in constexpr because of constexpr evaluation step limits
53 #if TEST_STD_VER > 20
54 static_assert(test());
55 #endif
57 return 0;