+2012-03-05 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/stl_algobase.h (iter_swap): In C++11 mode simply
+ call swap.
+ * include/bits/stl_bvector.h (swap(_Bit_reference,
+ _Bit_reference), swap(_Bit_reference, bool&),
+ swap(bool&, _Bit_reference)): Add.
+ * testsuite/23_containers/vector/bool/swap.cc: New.
+
2012-03-04 Paolo Carlini <paolo.carlini@oracle.com>
Jonathan Wakely <jwakely.gcc@gmail.com>
// Core algorithmic facilities -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011 Free Software Foundation, Inc.
+// 2011, 2012 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
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
// See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
// nutshell, we are partially implementing the resolution of DR 187,
// when it's safe, i.e., the value_types are equal.
swap(*__a, *__b);
}
};
+#endif
/**
* @brief Swaps the contents of two iterators.
inline void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
{
- typedef typename iterator_traits<_ForwardIterator1>::value_type
- _ValueType1;
- typedef typename iterator_traits<_ForwardIterator2>::value_type
- _ValueType2;
-
// concept requirements
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator1>)
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator2>)
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+ typedef typename iterator_traits<_ForwardIterator1>::value_type
+ _ValueType1;
+ typedef typename iterator_traits<_ForwardIterator2>::value_type
+ _ValueType2;
+
__glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
_ValueType2>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
&& __are_same<_ValueType1&, _ReferenceType1>::__value
&& __are_same<_ValueType2&, _ReferenceType2>::__value>::
iter_swap(__a, __b);
+#else
+ swap(*__a, *__b);
+#endif
}
/**
{ *_M_p ^= _M_mask; }
};
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ inline void
+ swap(_Bit_reference __x, _Bit_reference __y) noexcept
+ {
+ bool __tmp = __x;
+ __x = __y;
+ __y = __tmp;
+ }
+
+ inline void
+ swap(_Bit_reference __x, bool& __y) noexcept
+ {
+ bool __tmp = __x;
+ __x = __y;
+ __y = __tmp;
+ }
+
+ inline void
+ swap(bool& __x, _Bit_reference __y) noexcept
+ {
+ bool __tmp = __x;
+ __x = __y;
+ __y = __tmp;
+ }
+#endif
+
struct _Bit_iterator_base
: public std::iterator<std::random_access_iterator_tag, bool>
{
--- /dev/null
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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/>.
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+template<class Cont>
+ void
+ my_reverse(Cont& c)
+ {
+ for (std::size_t i = 0, j = c.size(); i < j; ++i)
+ {
+ --j;
+ using std::swap;
+ swap(c[i], c[j]);
+ }
+ }
+
+template<class Cont>
+ void
+ my_compare(const Cont& c1, const Cont& c2)
+ {
+ bool test __attribute__((unused)) = true;
+
+ VERIFY( c1.size() == c2.size() );
+
+ for (std::size_t i = 0; i < c1.size(); ++i)
+ VERIFY( c1[i] == c2[c1.size() - i - 1] );
+ }
+
+void test01()
+{
+ const std::vector<bool> vb_ref{0, 1, 1, 0, 1};
+ std::vector<bool> vb(vb_ref);
+ my_reverse(vb);
+ my_compare(vb_ref, vb);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}