]> 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
b9e8095b 1// 1999-06-08 bkoz
2
f1717362 3// Copyright (C) 1999-2016 Free Software Foundation, Inc.
b9e8095b 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
b9e8095b 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
b9e8095b 19
20// 23.3.5.1 bitset constructors
21
22#include <string>
23#include <bitset>
b83f6bce 24#include <algorithm> // std::reverse
8c8d0a56 25#include <stdexcept>
0194306c 26#include <testsuite_hooks.h>
b9e8095b 27
28bool test01(void)
29{
f8ef786c 30 bool test __attribute__((unused)) = true;
b9e8095b 31
32 // bitset()
33 const size_t n1 = 5;
34 std::bitset<n1> bit01;
f8ef786c 35 for (size_t i = 0; i < n1; ++i)
43a8c05a 36 VERIFY( !bit01.test(i) );
b9e8095b 37
38 // bitset(unsigned long)
39 const size_t n2 = 32;
40 unsigned long ul1 = 2;
41 std::bitset<n2> bit02(ul1);
43a8c05a 42 VERIFY( !bit02.test(0) );
43 VERIFY( bit02.test(1) );
44 VERIFY( !bit02.test(2) );
b9e8095b 45
46 // template<_CharT, _Traits, _Alloc>
47 // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n)
48 std::string str01("stuff smith sessions");
49 const size_t n3 = 128;
50 try {
51 std::bitset<n3> bit03(str01, 5);
52 }
53 catch(std::invalid_argument& fail) {
43a8c05a 54 VERIFY( true );
b9e8095b 55 }
56 catch(...) {
43a8c05a 57 VERIFY( false );
b9e8095b 58 }
59
60 std::string str02("010101000011");
61 int sz = str02.size();
62 try {
63 std::bitset<n3> bit03(str02, 0);
64 std::string str03;
65 for (int i = 0; i < sz; ++i)
66 str03 += (bit03.test(i) ? '1' : '0');
c245d928 67 std::reverse(str03.begin(), str03.end());
43a8c05a 68 VERIFY( str03 == str02 );
b9e8095b 69 }
70 catch(std::invalid_argument& fail) {
43a8c05a 71 VERIFY( false );
b9e8095b 72 }
73 catch(...) {
43a8c05a 74 VERIFY( false );
b9e8095b 75 }
b9e8095b 76 return test;
77}
78
79int main()
80{
81 test01();
b9e8095b 82 return 0;
83}