OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [23_containers/] [bitset/] [cons/] [1.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.