]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/bitset/cons/dr1325-2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / bitset / cons / dr1325-2.cc
1 // { dg-do run { target c++11 } }
2
3 // 2010-10-11 Paolo Carlini <paolo.carlini@oracle.com>
4
5 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 #include <bitset>
23 #include <testsuite_hooks.h>
24
25 template<std::size_t Nb, typename CharT>
26 std::bitset<Nb>
27 test01_ref(const CharT* str,
28 typename std::basic_string<CharT>::size_type n
29 = std::basic_string<CharT>::npos,
30 CharT zero = CharT('0'), CharT one = CharT('1'))
31 {
32 return std::bitset<Nb>(n == std::basic_string<CharT>::npos
33 ? std::basic_string<CharT>(str)
34 : std::basic_string<CharT>(str, n),
35 0, n, zero, one);
36 }
37
38 // DR 1325.
39 void test01()
40 {
41 using namespace std;
42
43 const char s1[4] = { '0', '1', '0', '1' };
44 VERIFY( bitset<4>(s1, 4) == test01_ref<4>(s1, 4) );
45
46 const char s2[3] = { '1', '1', '0' };
47 VERIFY( bitset<6>(s2, 3) == test01_ref<6>(s2, 3) );
48
49 const char* s3 = "1110110";
50 VERIFY( bitset<7>(s3) == test01_ref<7>(s3) );
51
52 const char* s4 = "0011";
53 VERIFY( bitset<10>(s4) == test01_ref<10>(s4) );
54
55 const char* s5 = "011110000111001";
56 VERIFY( bitset<5>(s5) == test01_ref<5>(s5) );
57
58 const char* s6 = "1cc1c1";
59 VERIFY( bitset<6>(s6, basic_string<char>::npos, 'c')
60 == test01_ref<6>(s6, basic_string<char>::npos, 'c') );
61
62 const char* s7 = "001011101";
63 VERIFY( bitset<9>(s7, basic_string<char>::npos, '0', '1')
64 == test01_ref<9>(s7, basic_string<char>::npos, '0', '1') );
65
66 const char* s8 = "babb";
67 VERIFY( bitset<4>(s8, basic_string<char>::npos, 'a', 'b')
68 == test01_ref<4>(s8, basic_string<char>::npos, 'a', 'b') );
69
70 const char* s9 = "bbabbbaaa";
71 VERIFY( bitset<100>(s9, basic_string<char>::npos, 'a', 'b')
72 == test01_ref<100>(s9, basic_string<char>::npos, 'a', 'b') );
73 }
74
75 int main()
76 {
77 test01();
78 return 0;
79 }