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