This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
2009/12/24 Paolo Carlini:Here is a new patch incorporating the test changes suggested by Jonathan and removing the stupid paste-o size_t thing.
Jon, when you have the time, I think we have also another special case
in <functional> which could be improved, maybe for std::function itself,
please help me figuring out the details, I noticed this issue a lot of
time ago. Anyway, I think the issue is that we don't have overloads /
specializations for variadic functions: we catch elegantly any number of
arguments with variadic templates but we don't catch variadic functions
themselves. I think the std::is_function trait is already ok, however.
You mean old fashioned variadic "..." functions like printf? Hmm, I hadn't thought of that - I'll look into it.
Index: libstdc++-v3/include/std/bitset =================================================================== --- libstdc++-v3/include/std/bitset (revision 155433) +++ libstdc++-v3/include/std/bitset (working copy) @@ -76,11 +76,21 @@ _Base_bitset() { _M_do_reset(); } +#if defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_LONG_LONG) + _Base_bitset(unsigned long long __val) + { + _M_do_reset(); + const size_t __n = sizeof(unsigned long long) / sizeof(unsigned long); + for (size_t __i = 0; __i < __n && __i < _Nw; ++__i) + _M_w[__i] = __val >> (__i * _GLIBCXX_BITSET_BITS_PER_WORD); + } +#else _Base_bitset(unsigned long __val) { _M_do_reset(); _M_w[0] = __val; } +#endif static size_t _S_whichword(size_t __pos ) @@ -199,6 +209,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 +289,25 @@ return _M_w[0]; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef _GLIBCXX_USE_LONG_LONG template<size_t _Nw> + unsigned long long + _Base_bitset<_Nw>::_M_do_to_ullong() const + { + const size_t __n = sizeof(unsigned long long) / sizeof(unsigned long); + for (size_t __i = __n; __i < _Nw; ++__i) + if (_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 < _Nw; ++__i) + __res += _M_w[__i] << (__i * _GLIBCXX_BITSET_BITS_PER_WORD); + return __res; + } +#endif +#endif + + template<size_t _Nw> size_t _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const { @@ -337,9 +372,15 @@ : _M_w(0) { } +#if defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_LONG_LONG) + _Base_bitset(unsigned long long __val) + : _M_w(static_cast<unsigned long>(__val)) + { } +#else _Base_bitset(unsigned long __val) : _M_w(__val) { } +#endif static size_t _S_whichword(size_t __pos ) @@ -425,6 +466,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 { @@ -463,8 +512,13 @@ _Base_bitset() { } +#if defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_LONG_LONG) + _Base_bitset(unsigned long long) + { } +#else _Base_bitset(unsigned long) { } +#endif static size_t _S_whichword(size_t __pos ) @@ -555,6 +609,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 @@ -737,9 +799,15 @@ { } /// Initial bits bitwise-copied from a single word (others set to zero). +#if defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_LONG_LONG) + bitset(unsigned long long __val) + : _Base(__val) + { _M_do_sanitize(); } +#else bitset(unsigned long __val) : _Base(__val) { _M_do_sanitize(); } +#endif /** * @brief Use a subset of a string. @@ -798,6 +866,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() + { + if (__str) + { + const size_t __len = __builtin_strlen(__str); + _M_copy_from_ptr<char, std::char_traits<char>> + (__str, __len, 0, __len, '0', '1'); + } + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + // 23.3.5.2 bitset operations: //@{ /** @@ -1019,6 +1107,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: libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc (revision 0) +++ libstdc++-v3/testsuite/23_containers/bitset/cons/2.cc (revision 0) @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-23 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 +// <http://www.gnu.org/licenses/>. + +// 23.3.7.1 bitset const char * constructor. + +#include <bitset> +#include <string> +#include <testsuite_hooks.h> + +struct X +{ + operator const char* () { return "10101010"; } +}; + +bool +test01() +{ + bool test __attribute__((unused)) = true; + + X x; + std::string s(x); + std::bitset<32> b1(x); + std::bitset<32> b2(s); + VERIFY( b1 == b2 ); + + return test; +} + +int +main() +{ + test01(); + return 0; +} Index: libstdc++-v3/testsuite/23_containers/bitset/to_ulong/2.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/bitset/to_ulong/2.cc (revision 0) +++ libstdc++-v3/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 +// <http://www.gnu.org/licenses/>. + +// 23.3.7.2 bitset members + +#include <bitset> +#include <stdexcept> +#include <sstream> +#include <testsuite_hooks.h> + +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; +}
Index: include/std/bitset =================================================================== --- include/std/bitset (revision 155433) +++ include/std/bitset (working copy) @@ -798,6 +798,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() + { + if (__str) + { + const size_t __len = __builtin_strlen(__str); + _M_copy_from_ptr<char, std::char_traits<char>> + (__str, __len, 0, __len, '0', '1'); + } + } +#endif // __GXX_EXPERIMENTAL_CXX0X__ + // 23.3.5.2 bitset operations: //@{ /** 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,52 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-23 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 +// <http://www.gnu.org/licenses/>. + +// 23.3.7.1 bitset const char * constructor. + +#include <bitset> +#include <string> +#include <testsuite_hooks.h> + +struct X +{ + operator const char* () { return "10101010"; } +}; + +bool +test01() +{ + bool test __attribute__((unused)) = true; + + X x; + std::string s(x); + std::bitset<32> b1(x); + std::bitset<32> b2(s); + VERIFY( b1 == b2 ); + + return test; +} + +int +main() +{ + test01(); + return 0; +}
Attachment:
CL_bitset_0x
Description: video/flv
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |