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~() const; |
| 11 | |
| 12 | #include <bitset> |
| 13 | #include <cstdlib> |
| 14 | #include <cassert> |
| 15 | |
Howard Hinnant | 97ecd64 | 2011-05-17 19:12:55 +0000 | [diff] [blame] | 16 | #pragma clang diagnostic ignored "-Wtautological-compare" |
| 17 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 18 | template <std::size_t N> |
| 19 | std::bitset<N> |
| 20 | make_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 | |
| 28 | template <std::size_t N> |
| 29 | void test_not_all() |
| 30 | { |
| 31 | std::bitset<N> v1 = make_bitset<N>(); |
| 32 | std::bitset<N> v2 = ~v1; |
| 33 | for (std::size_t i = 0; i < N; ++i) |
| 34 | assert(v2[i] == ~v1[i]); |
| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | test_not_all<0>(); |
| 40 | test_not_all<1>(); |
| 41 | test_not_all<31>(); |
| 42 | test_not_all<32>(); |
| 43 | test_not_all<33>(); |
| 44 | test_not_all<63>(); |
| 45 | test_not_all<64>(); |
| 46 | test_not_all<65>(); |
| 47 | test_not_all<1000>(); |
| 48 | } |