Index: include/std/bitset =================================================================== --- include/std/bitset (revision 155320) +++ include/std/bitset (working copy) @@ -199,6 +199,13 @@ unsigned long _M_do_to_ulong() const; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long + _M_do_to_ullong() const; +#endif +#endif + // find first "on" bit size_t _M_do_find_first(size_t __not_found) const; @@ -272,7 +279,25 @@ return _M_w[0]; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG template + unsigned long long + _Base_bitset<_Nw>::_M_do_to_ullong() const + { + size_t __n = sizeof(unsigned long long) / sizeof(unsigned long); + for (size_t __i = __n; __i < this->_M_w.size(); ++__i) + if (this->_M_w[__i]) + __throw_overflow_error(__N("_Base_bitset::_M_do_to_ullong")); + unsigned long long __res = 0ULL; + for (size_t __i = 0; __i < __n && __i < this->_M_w.size(); ++__i) + __res += this->_M_w[__i] << (__i * _GLIBCXX_BITSET_BITS_PER_WORD); + return __res; + } +#endif +#endif + + template size_t _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const { @@ -425,6 +450,14 @@ _M_do_to_ulong() const { return _M_w; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long + _M_do_to_ullong() const + { return _M_w; } +#endif +#endif + size_t _M_do_find_first(size_t __not_found) const { @@ -555,6 +588,14 @@ _M_do_to_ulong() const { return 0; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long + _M_do_to_ullong() const + { return 0; } +#endif +#endif + // Normally "not found" is the size, but that could also be // misinterpreted as an index in this corner case. Oh well. size_t @@ -798,6 +839,26 @@ _M_copy_from_string(__s, __position, __n, __zero, __one); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Construct from a string. + * @param str A string of '0' and '1' characters. + * @throw std::invalid_argument If a character appears in the string + * which is neither '0' nor '1'. + */ + explicit + bitset(const char* __str) + : _Base() + { + size_t __len = 0; + if (__str) + while (__str[__len] != '\0') + ++__len; + this->_M_copy_from_ptr> + (__str, __len, 0, __len, '0', '1'); + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + // 23.3.5.2 bitset operations: //@{ /** @@ -1019,6 +1080,14 @@ to_ulong() const { return this->_M_do_to_ulong(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG + unsigned long long + to_ullong() const + { return this->_M_do_to_ullong(); } +#endif +#endif + /** * @brief Returns a character interpretation of the %bitset. * @return The string equivalent of the bits. Index: testsuite/23_containers/bitset/cons/2.cc =================================================================== --- testsuite/23_containers/bitset/cons/2.cc (revision 0) +++ testsuite/23_containers/bitset/cons/2.cc (revision 0) @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-16 emsr + +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.3.7.1 bitset char * constructor. + +#include +#include // std::reverse +#include +#include // std::str* +#include + +bool test01(void) +{ + bool test __attribute__((unused)) = true; + + const size_t n1 = 128; + const char * str01 = "010101000011"; + const int sz = std::strlen(str01); + char str02[sz + 1]; + std::strcpy(str02, " "); + try { + std::bitset bit01(str01); + for (int i = 0; i < sz; ++i) + str02[i] = (bit01.test(i) ? '1' : '0'); + std::reverse(str02, str02 + std::strlen(str02)); + VERIFY( std::strcmp(str02, str01) == 0 ); + } + catch(std::invalid_argument& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } + return test; +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/bitset/to_ulong/2.cc =================================================================== --- testsuite/23_containers/bitset/to_ulong/2.cc (revision 0) +++ testsuite/23_containers/bitset/to_ulong/2.cc (revision 0) @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-16 emsr + +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 23.3.7.2 bitset members + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + std::bitset<5> b; + std::stringstream ss("101"); + ss.exceptions(std::ios_base::eofbit); + + try + { + ss >> b; + } + catch (std::exception&) { } + + VERIFY( b.to_ullong() == 5 ); +} + +int main() +{ + test01(); + return 0; +}