This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] Implement DR 693


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

//////////////
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.
Index: docs/html/ext/howto.html
===================================================================
--- docs/html/ext/howto.html	(revision 130373)
+++ docs/html/ext/howto.html	(working copy)
@@ -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>
Index: include/debug/bitset
===================================================================
--- include/debug/bitset	(revision 130373)
+++ include/debug/bitset	(working copy)
@@ -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 @@
       { return _M_base() != __rhs; }
 
       using _Base::test;
+      using _Base::all;
       using _Base::any;
       using _Base::none;
 
Index: include/std/bitset
===================================================================
--- include/std/bitset	(revision 130373)
+++ include/std/bitset	(working copy)
@@ -170,21 +170,27 @@
       _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 @@
       _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 @@
       _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 @@
 	  __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 @@
       __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
Index: testsuite/23_containers/bitset/all/1.cc
===================================================================
--- testsuite/23_containers/bitset/all/1.cc	(revision 0)
+++ testsuite/23_containers/bitset/all/1.cc	(revision 0)
@@ -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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]