right_shift.pass.cpp revision c52f43e72dfcea03037729649da84c23b3beb04a
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// test bitset<N> operator>>(size_t pos) const;
11
12#include <bitset>
13#include <cstdlib>
14#include <cassert>
15
16template <std::size_t N>
17std::bitset<N>
18make_bitset()
19{
20    std::bitset<N> v;
21    for (std::size_t i = 0; i < N; ++i)
22        v[i] = static_cast<bool>(std::rand() & 1);
23    return v;
24}
25
26template <std::size_t N>
27void test_right_shift()
28{
29    for (std::size_t s = 0; s <= N+1; ++s)
30    {
31        std::bitset<N> v1 = make_bitset<N>();
32        std::bitset<N> v2 = v1;
33        assert((v1 >>= s) == (v2 >> s));
34    }
35}
36
37int main()
38{
39    test_right_shift<0>();
40    test_right_shift<1>();
41    test_right_shift<31>();
42    test_right_shift<32>();
43    test_right_shift<33>();
44    test_right_shift<63>();
45    test_right_shift<64>();
46    test_right_shift<65>();
47    test_right_shift<1000>();
48}
49