]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/bitset/cons/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / bitset / cons / 1.cc
CommitLineData
b2dad0e3
BK
1// 1999-06-08 bkoz
2
8d9254fc 3// Copyright (C) 1999-2020 Free Software Foundation, Inc.
b2dad0e3
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
b2dad0e3
BK
19
20// 23.3.5.1 bitset constructors
21
22#include <string>
23#include <bitset>
f56fe8ff 24#include <algorithm> // std::reverse
8dba028f 25#include <stdexcept>
fe413112 26#include <testsuite_hooks.h>
b2dad0e3 27
a9260b7e 28void test01(void)
b2dad0e3 29{
b2dad0e3
BK
30 // bitset()
31 const size_t n1 = 5;
32 std::bitset<n1> bit01;
11f10e6b 33 for (size_t i = 0; i < n1; ++i)
aa1b2f7d 34 VERIFY( !bit01.test(i) );
b2dad0e3
BK
35
36 // bitset(unsigned long)
37 const size_t n2 = 32;
38 unsigned long ul1 = 2;
39 std::bitset<n2> bit02(ul1);
aa1b2f7d
BV
40 VERIFY( !bit02.test(0) );
41 VERIFY( bit02.test(1) );
42 VERIFY( !bit02.test(2) );
b2dad0e3
BK
43
44 // template<_CharT, _Traits, _Alloc>
45 // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n)
46 std::string str01("stuff smith sessions");
47 const size_t n3 = 128;
48 try {
49 std::bitset<n3> bit03(str01, 5);
50 }
51 catch(std::invalid_argument& fail) {
aa1b2f7d 52 VERIFY( true );
b2dad0e3
BK
53 }
54 catch(...) {
aa1b2f7d 55 VERIFY( false );
b2dad0e3
BK
56 }
57
58 std::string str02("010101000011");
59 int sz = str02.size();
60 try {
61 std::bitset<n3> bit03(str02, 0);
62 std::string str03;
63 for (int i = 0; i < sz; ++i)
64 str03 += (bit03.test(i) ? '1' : '0');
97e0a05a 65 std::reverse(str03.begin(), str03.end());
aa1b2f7d 66 VERIFY( str03 == str02 );
b2dad0e3
BK
67 }
68 catch(std::invalid_argument& fail) {
aa1b2f7d 69 VERIFY( false );
b2dad0e3
BK
70 }
71 catch(...) {
aa1b2f7d 72 VERIFY( false );
b2dad0e3 73 }
b2dad0e3
BK
74}
75
76int main()
77{
78 test01();
b2dad0e3
BK
79 return 0;
80}