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
This commit is contained in:
Paolo Carlini 2007-11-23 22:14:56 +00:00 committed by Paolo Carlini
parent b6f63e8984
commit b96817da11
5 changed files with 133 additions and 49 deletions

View File

@ -1,3 +1,14 @@
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.
2007-11-23 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_list.h (insert(iterator, value_type&&)): Just

View File

@ -639,6 +639,12 @@
<dd>Add the missing operations.
</dd>
<dt><a href="lwg-active.html#693">693</a>:
<em>std::bitset::all() missing</em>
</dt>
<dd>Add it, consistently with the discussion.
</dd>
<dt><a href="lwg-active.html#695">695</a>:
<em>ctype&lt;char&gt;::classic_table() not accessible</em>
</dt>

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,81 @@
// 2007-11-23 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, 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 COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.3.5.2 bitset members
#include <bitset>
#include <testsuite_hooks.h>
// DR 693. std::bitset::all() missing.
void test01()
{
bool test __attribute__((unused)) = true;
std::bitset<0> z1;
VERIFY( z1.all() );
z1.set();
VERIFY( z1.all() );
std::bitset<8> z2;
VERIFY( !z2.all() );
z2.set();
VERIFY( z2.all() );
std::bitset<16> z3;
VERIFY( !z3.all() );
z3.set();
VERIFY( z3.all() );
std::bitset<32> z4;
VERIFY( !z4.all() );
z4.set();
VERIFY( z4.all() );
std::bitset<64> z5;
VERIFY( !z5.all() );
z5.set();
VERIFY( z5.all() );
std::bitset<96> z6;
VERIFY( !z6.all() );
z6.set();
VERIFY( z6.all() );
std::bitset<128> z7;
VERIFY( !z7.all() );
z7.set();
VERIFY( z7.all() );
std::bitset<192> z8;
VERIFY( !z8.all() );
z8.set();
VERIFY( z8.all() );
std::bitset<1024> z9;
VERIFY( !z9.all() );
z9.set();
VERIFY( z9.all() );
}
int main()
{
test01();
return 0;
}