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 // template <class charT> 12 // explicit bitset(const charT* str, 13 // typename basic_string<charT>::size_type n = basic_string<charT>::npos, 14 // charT zero = charT('0'), charT one = charT('1')); 15 16 #include <bitset> 17 #include <cassert> 18 #include <algorithm> // for 'min' and 'max' 19 #include <stdexcept> // for 'invalid_argument' 20 21 #pragma clang diagnostic ignored "-Wtautological-compare" 22 23 template <std::size_t N> 24 void test_char_pointer_ctor() 25 { 26 { 27 try 28 { 29 std::bitset<N> v("xxx1010101010xxxx"); 30 assert(false); 31 } 32 catch (std::invalid_argument&) 33 { 34 } 35 } 36 37 { 38 const char str[] ="1010101010"; 39 std::bitset<N> v(str); 40 std::size_t M = std::min<std::size_t>(N, 10); 41 for (std::size_t i = 0; i < M; ++i) 42 assert(v[i] == (str[M - 1 - i] == '1')); 43 for (std::size_t i = 10; i < N; ++i) 44 assert(v[i] == false); 45 } 46 } 47 48 int main() 49 { 50 test_char_pointer_ctor<0>(); 51 test_char_pointer_ctor<1>(); 52 test_char_pointer_ctor<31>(); 53 test_char_pointer_ctor<32>(); 54 test_char_pointer_ctor<33>(); 55 test_char_pointer_ctor<63>(); 56 test_char_pointer_ctor<64>(); 57 test_char_pointer_ctor<65>(); 58 test_char_pointer_ctor<1000>(); 59 } 60