1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// test bitset<N>& operator<<=(size_t pos);
11
12#include <bitset>
13#include <cstdlib>
14#include <cassert>
15
16#pragma clang diagnostic ignored "-Wtautological-compare"
17
18template <std::size_t N>
19std::bitset<N>
20make_bitset()
21{
22    std::bitset<N> v;
23    for (std::size_t i = 0; i < N; ++i)
24        v[i] = static_cast<bool>(std::rand() & 1);
25    return v;
26}
27
28template <std::size_t N>
29void test_left_shift()
30{
31    for (std::size_t s = 0; s <= N+1; ++s)
32    {
33        std::bitset<N> v1 = make_bitset<N>();
34        std::bitset<N> v2 = v1;
35        v1 <<= s;
36        for (std::size_t i = 0; i < N; ++i)
37            if (i < s)
38                assert(v1[i] == 0);
39            else
40                assert(v1[i] == v2[i-s]);
41    }
42}
43
44int main()
45{
46    test_left_shift<0>();
47    test_left_shift<1>();
48    test_left_shift<31>();
49    test_left_shift<32>();
50    test_left_shift<33>();
51    test_left_shift<63>();
52    test_left_shift<64>();
53    test_left_shift<65>();
54    test_left_shift<1000>();
55}
56