Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // test bitset<N> operator>>(size_t pos) const; |
| 11 | |
| 12 | #include <bitset> |
| 13 | #include <cstdlib> |
| 14 | #include <cassert> |
| 15 | |
Eric Fiselier | 4596c29 | 2016-04-28 01:49:03 +0000 | [diff] [blame] | 16 | #if defined(__clang__) |
Howard Hinnant | 97ecd64 | 2011-05-17 19:12:55 +0000 | [diff] [blame] | 17 | #pragma clang diagnostic ignored "-Wtautological-compare" |
Eric Fiselier | 4596c29 | 2016-04-28 01:49:03 +0000 | [diff] [blame] | 18 | #endif |
Howard Hinnant | 97ecd64 | 2011-05-17 19:12:55 +0000 | [diff] [blame] | 19 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 20 | template <std::size_t N> |
| 21 | std::bitset<N> |
| 22 | make_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 | |
| 30 | template <std::size_t N> |
| 31 | void 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 | |
| 41 | int 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 | } |