1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // test constexpr bool test(size_t pos) const; 11 12 #include <bitset> 13 #include <cstdlib> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 template <std::size_t N> 19 std::bitset<N> make_bitset()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 28 template <std::size_t N> test_test(bool test_throws)29void test_test(bool test_throws) 30 { 31 const std::bitset<N> v1 = make_bitset<N>(); 32 #ifdef TEST_HAS_NO_EXCEPTIONS 33 if (test_throws) return; 34 #else 35 try 36 { 37 #endif 38 bool b = v1.test(50); 39 if (50 >= v1.size()) 40 assert(false); 41 assert(b == v1[50]); 42 assert(!test_throws); 43 #ifndef TEST_HAS_NO_EXCEPTIONS 44 } 45 catch (std::out_of_range&) 46 { 47 assert(test_throws); 48 } 49 #endif 50 } 51 main()52int main() 53 { 54 test_test<0>(true); 55 test_test<1>(true); 56 test_test<31>(true); 57 test_test<32>(true); 58 test_test<33>(true); 59 test_test<63>(false); 60 test_test<64>(false); 61 test_test<65>(false); 62 test_test<1000>(false); 63 } 64