blob: 87fcc281fa26ec50b5125670b95390353bd03491 [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// test bitset<N> operator>>(size_t pos) const;
11
12#include <bitset>
13#include <cstdlib>
14#include <cassert>
15
Howard Hinnant97ecd642011-05-17 19:12:55 +000016#pragma clang diagnostic ignored "-Wtautological-compare"
17
Howard Hinnantc52f43e2010-08-22 00:59:46 +000018template <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_right_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 assert((v1 >>= s) == (v2 >> s));
36 }
37}
38
39int main()
40{
41 test_right_shift<0>();
42 test_right_shift<1>();
43 test_right_shift<31>();
44 test_right_shift<32>();
45 test_right_shift<33>();
46 test_right_shift<63>();
47 test_right_shift<64>();
48 test_right_shift<65>();
49 test_right_shift<1000>();
50}