xref: /llvm-project/libcxx/test/std/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp (revision 91876eab93a9f0ef29a339ed99bdb1c8ed1e85c6)
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 // ADDITIONAL_COMPILE_FLAGS(has-fconstexpr-steps): -fconstexpr-steps=15000000
10 
11 // bitset<N>& operator|=(const bitset<N>& rhs); // constexpr since C++23
12 
13 #include <bitset>
14 #include <cassert>
15 #include <cstddef>
16 #include <vector>
17 
18 #include "../bitset_test_cases.h"
19 #include "test_macros.h"
20 
21 template <std::size_t N>
test_op_or_eq()22 TEST_CONSTEXPR_CXX23 void test_op_or_eq() {
23     std::vector<std::bitset<N> > const cases = get_test_cases<N>();
24     for (std::size_t c1 = 0; c1 != cases.size(); ++c1) {
25         for (std::size_t c2 = 0; c2 != cases.size(); ++c2) {
26             std::bitset<N> v1 = cases[c1];
27             std::bitset<N> v2 = cases[c2];
28             std::bitset<N> v3 = v1;
29             v1 |= v2;
30             for (std::size_t i = 0; i < v1.size(); ++i)
31                 assert(v1[i] == (v3[i] || v2[i]));
32         }
33     }
34 }
35 
test()36 TEST_CONSTEXPR_CXX23 bool test() {
37   test_op_or_eq<0>();
38   test_op_or_eq<1>();
39   test_op_or_eq<31>();
40   test_op_or_eq<32>();
41   test_op_or_eq<33>();
42   test_op_or_eq<63>();
43   test_op_or_eq<64>();
44   test_op_or_eq<65>();
45 
46   return true;
47 }
48 
main(int,char **)49 int main(int, char**) {
50   test();
51   test_op_or_eq<1000>(); // not in constexpr because of constexpr evaluation step limits
52 #if TEST_STD_VER > 20
53   static_assert(test());
54 #endif
55 
56   return 0;
57 }
58