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 // XFAIL: libcpp-no-exceptions 11 // test constexpr bool test(size_t pos) const; 12 13 #include <bitset> 14 #include <cstdlib> 15 #include <cassert> 16 17 template <std::size_t N> 18 std::bitset<N> 19 make_bitset() 20 { 21 std::bitset<N> v; 22 for (std::size_t i = 0; i < N; ++i) 23 v[i] = static_cast<bool>(std::rand() & 1); 24 return v; 25 } 26 27 template <std::size_t N> 28 void test_test() 29 { 30 const std::bitset<N> v1 = make_bitset<N>(); 31 try 32 { 33 bool b = v1.test(50); 34 if (50 >= v1.size()) 35 assert(false); 36 assert(b == v1[50]); 37 } 38 catch (std::out_of_range&) 39 { 40 } 41 } 42 43 int main() 44 { 45 test_test<0>(); 46 test_test<1>(); 47 test_test<31>(); 48 test_test<32>(); 49 test_test<33>(); 50 test_test<63>(); 51 test_test<64>(); 52 test_test<65>(); 53 test_test<1000>(); 54 } 55