blob: 180fa84f4488b5c1dcf58f861a578423e8b00628 [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
Eric Fiselier4596c292016-04-28 01:49:03 +000016#if defined(__clang__)
Howard Hinnant97ecd642011-05-17 19:12:55 +000017#pragma clang diagnostic ignored "-Wtautological-compare"
Eric Fiselier4596c292016-04-28 01:49:03 +000018#endif
Howard Hinnant97ecd642011-05-17 19:12:55 +000019
Howard Hinnantc52f43e2010-08-22 00:59:46 +000020template <std::size_t N>
21std::bitset<N>
22make_bitset()
23{
24 std::bitset<N> v;
25 for (std::size_t i = 0; i < N; ++i)
26 v[i] = static_cast<bool>(std::rand() & 1);
27 return v;
28}
29
30template <std::size_t N>
31void test_right_shift()
32{
33 for (std::size_t s = 0; s <= N+1; ++s)
34 {
35 std::bitset<N> v1 = make_bitset<N>();
36 std::bitset<N> v2 = v1;
37 assert((v1 >>= s) == (v2 >> s));
38 }
39}
40
41int main()
42{
43 test_right_shift<0>();
44 test_right_shift<1>();
45 test_right_shift<31>();
46 test_right_shift<32>();
47 test_right_shift<33>();
48 test_right_shift<63>();
49 test_right_shift<64>();
50 test_right_shift<65>();
51 test_right_shift<1000>();
52}