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