diff options
author | Paolo Carlini <pcarlini@suse.de> | 2007-11-23 22:14:56 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2007-11-23 22:14:56 +0000 |
commit | b96817da11c613095421177f06a1936a3e9bbf54 (patch) | |
tree | f16dc3eecc9e9271a4876d22bcbf54c119f7810f /libstdc++-v3/include | |
parent | b6f63e898498e62e78b51ee135fd8dc686c11d60 (diff) | |
download | gcc-b96817da11c613095421177f06a1936a3e9bbf54.zip gcc-b96817da11c613095421177f06a1936a3e9bbf54.tar.gz gcc-b96817da11c613095421177f06a1936a3e9bbf54.tar.bz2 |
bitset (bitset<>::all): Add, per DR 693 [Ready].
2007-11-23 Paolo Carlini <pcarlini@suse.de>
* include/std/bitset (bitset<>::all): Add, per DR 693 [Ready].
(_Base_bitset<>::_M_are_all_aux()): Add.
* include/debug/bitset (bitset<>::all): Add.
* testsuite/23_containers/bitset/all/1.cc: New.
* docs/html/ext/howto.html: Add an entry for DR 693.
* include/std/bitset (bitset<0>::set, reset, flip, test): Remove,
not necessary anymore.
From-SVN: r130384
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/debug/bitset | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/std/bitset | 80 |
2 files changed, 35 insertions, 49 deletions
diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index ba67712..db4b3c0 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -1,7 +1,6 @@ // Debugging bitset implementation -*- C++ -*- -// Copyright (C) 2003, 2004, 2005 -// Free Software Foundation, Inc. +// Copyright (C) 2003, 2004, 2005, 2006, 2007 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 @@ -279,6 +278,7 @@ namespace __debug { return _M_base() != __rhs; } using _Base::test; + using _Base::all; using _Base::any; using _Base::none; diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index c9f9111..9a984d03 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -170,21 +170,27 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_is_equal(const _Base_bitset<_Nw>& __x) const { for (size_t __i = 0; __i < _Nw; ++__i) - { - if (_M_w[__i] != __x._M_w[__i]) - return false; - } + if (_M_w[__i] != __x._M_w[__i]) + return false; return true; } + size_t + _M_are_all_aux() const + { + for (size_t __i = 0; __i < _Nw - 1; __i++) + if (_M_w[__i] != ~static_cast<_WordT>(0)) + return 0; + return ((_Nw - 1) * _GLIBCXX_BITSET_BITS_PER_WORD + + __builtin_popcountl(_M_hiword())); + } + bool _M_is_any() const { for (size_t __i = 0; __i < _Nw; __i++) - { - if (_M_w[__i] != static_cast<_WordT>(0)) - return true; - } + if (_M_w[__i] != static_cast<_WordT>(0)) + return true; return false; } @@ -412,6 +418,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_is_equal(const _Base_bitset<1>& __x) const { return _M_w == __x._M_w; } + size_t + _M_are_all_aux() const + { return __builtin_popcountl(_M_w); } + bool _M_is_any() const { return _M_w != 0; } @@ -540,6 +550,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_is_equal(const _Base_bitset<0>&) const { return true; } + size_t + _M_are_all_aux() const + { return 0; } + bool _M_is_any() const { return false; } @@ -1089,7 +1103,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) __throw_out_of_range(__N("bitset::test")); return _Unchecked_test(__position); } - + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 693. std::bitset::all() missing. + /** + * @brief Tests whether all the bits are on. + * @return True if all the bits are set. + */ + bool + all() const + { return this->_M_are_all_aux() == _Nb; } + /** * @brief Tests whether any of the bits are on. * @return True if at least one bit is set. @@ -1298,44 +1322,6 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) __x._M_copy_to_string(__tmp); return __os << __tmp; } - - // Specializations for zero-sized bitsets, to avoid "unsigned comparison - // with zero" warnings. - template<> - inline bitset<0>& - bitset<0>:: - set(size_t, bool) - { - __throw_out_of_range(__N("bitset::set")); - return *this; - } - - template<> - inline bitset<0>& - bitset<0>:: - reset(size_t) - { - __throw_out_of_range(__N("bitset::reset")); - return *this; - } - - template<> - inline bitset<0>& - bitset<0>:: - flip(size_t) - { - __throw_out_of_range(__N("bitset::flip")); - return *this; - } - - template<> - inline bool - bitset<0>:: - test(size_t) const - { - __throw_out_of_range(__N("bitset::test")); - return false; - } //@} _GLIBCXX_END_NESTED_NAMESPACE |