xref: /llvm-project/libcxx/test/std/utilities/template.bitset/bitset.members/right_shift_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<<=(size_t pos); // 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_right_shift()22 TEST_CONSTEXPR_CXX23 bool test_right_shift() {
23     std::vector<std::bitset<N> > const cases = get_test_cases<N>();
24     for (std::size_t c = 0; c != cases.size(); ++c) {
25         for (std::size_t s = 0; s <= N+1; ++s) {
26             std::bitset<N> v1 = cases[c];
27             std::bitset<N> v2 = v1;
28             v1 >>= s;
29             for (std::size_t i = 0; i < v1.size(); ++i)
30                 if (i + s < v1.size())
31                     assert(v1[i] == v2[i + s]);
32                 else
33                     assert(v1[i] == 0);
34         }
35     }
36     return true;
37 }
38 
main(int,char **)39 int main(int, char**) {
40   test_right_shift<0>();
41   test_right_shift<1>();
42   test_right_shift<31>();
43   test_right_shift<32>();
44   test_right_shift<33>();
45   test_right_shift<63>();
46   test_right_shift<64>();
47   test_right_shift<65>();
48   test_right_shift<1000>(); // not in constexpr because of constexpr evaluation step limits
49 #if TEST_STD_VER > 20
50   static_assert(test_right_shift<0>());
51   static_assert(test_right_shift<1>());
52   static_assert(test_right_shift<31>());
53   static_assert(test_right_shift<32>());
54   static_assert(test_right_shift<33>());
55   static_assert(test_right_shift<63>());
56   static_assert(test_right_shift<64>());
57   static_assert(test_right_shift<65>());
58 #endif
59 
60   return 0;
61 }
62