[libstdc++] swap() in vector<bool>

Phil Edwards phil@jaj.com
Sun Jun 2 22:04:00 GMT 2002


At the start of May, Stephen Webb found some weirdness in stl_bvector.h:

    http://gcc.gnu.org/ml/libstdc++/2002-05/msg00079.html

The followup discussion

    http://gcc.gnu.org/ml/libstdc++/2002-05/subjects.html#00099

led to the patch below.  The standard specifies a static vector member
function that we/SGI never had, and we/SGI have a namespace-level function
that the standard never specified.  Oops.

Moving the function into std::vector<bool>, and changing the signature to
match, not only brings us closer to conformance, but avoids the possibility
of misleading error messages that Stephen discovered.

Tested on i686-pc-linux-gnu.  Applied to trunk.  I'd like to apply it to
the branch, but I don't know if the problem is big enough.



2002-06-03  Phil Edwards  <pme@gcc.gnu.org>

	* include/bits/stl_bvector.h (swap(_Bit_reference,_Bit_reference)):
	Move/rename...
	(vector<bool>::swap(reference,reference)): ...to this.


Index: include/bits/stl_bvector.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_bvector.h,v
retrieving revision 1.15
diff -u -3 -p -r1.15 stl_bvector.h
--- include/bits/stl_bvector.h	1 Jun 2002 00:48:21 -0000	1.15
+++ include/bits/stl_bvector.h	3 Jun 2002 05:01:58 -0000
@@ -91,13 +91,6 @@ public:
   void flip() { *_M_p ^= _M_mask; }
 };
 
-inline void swap(_Bit_reference __x, _Bit_reference __y)
-{
-  bool __tmp = __x;
-  __x = __y;
-  __y = __tmp;
-}
-
 struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
 {
   _Bit_type * _M_p;
@@ -635,6 +628,14 @@ template <typename _Alloc> 
       std::swap(_M_finish, __x._M_finish);
       std::swap(_M_end_of_storage, __x._M_end_of_storage);
     }
+
+    // [23.2.5]/1, third-to-last entry in synopsis listing
+    static void swap(reference __x, reference __y) {
+      bool __tmp = __x;
+      __x = __y;
+      __y = __tmp;
+    }
+
     iterator insert(iterator __position, bool __x = bool()) {
       difference_type __n = __position - begin();
       if (_M_finish._M_p != _M_end_of_storage && __position == end())



More information about the Libstdc++ mailing list