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