Commit 93d9a365 by Paolo Carlini Committed by Paolo Carlini

stl_algobase.h (iter_swap): In C++11 mode just call swap.

2012-03-05  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/stl_algobase.h (iter_swap): In C++11 mode just
	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.

From-SVN: r184939
parent 510dbcce
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> 2012-03-04 Paolo Carlini <paolo.carlini@oracle.com>
Jonathan Wakely <jwakely.gcc@gmail.com> Jonathan Wakely <jwakely.gcc@gmail.com>
......
// Core algorithmic facilities -*- C++ -*- // Core algorithmic facilities -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -74,6 +74,7 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -74,6 +74,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifndef __GXX_EXPERIMENTAL_CXX0X__
// See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
// nutshell, we are partially implementing the resolution of DR 187, // nutshell, we are partially implementing the resolution of DR 187,
// when it's safe, i.e., the value_types are equal. // when it's safe, i.e., the value_types are equal.
...@@ -102,6 +103,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -102,6 +103,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
swap(*__a, *__b); swap(*__a, *__b);
} }
}; };
#endif
/** /**
* @brief Swaps the contents of two iterators. * @brief Swaps the contents of two iterators.
...@@ -117,16 +119,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -117,16 +119,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline void inline void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
{ {
typedef typename iterator_traits<_ForwardIterator1>::value_type
_ValueType1;
typedef typename iterator_traits<_ForwardIterator2>::value_type
_ValueType2;
// concept requirements // concept requirements
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept< __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator1>) _ForwardIterator1>)
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept< __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator2>) _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, __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
_ValueType2>) _ValueType2>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType2, __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
...@@ -140,6 +144,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -140,6 +144,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __are_same<_ValueType1&, _ReferenceType1>::__value && __are_same<_ValueType1&, _ReferenceType1>::__value
&& __are_same<_ValueType2&, _ReferenceType2>::__value>:: && __are_same<_ValueType2&, _ReferenceType2>::__value>::
iter_swap(__a, __b); iter_swap(__a, __b);
#else
swap(*__a, *__b);
#endif
} }
/** /**
......
...@@ -108,6 +108,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -108,6 +108,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ *_M_p ^= _M_mask; } { *_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 struct _Bit_iterator_base
: public std::iterator<std::random_access_iterator_tag, bool> : public std::iterator<std::random_access_iterator_tag, bool>
{ {
......
// { 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment