aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2012-03-05 16:31:50 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2012-03-05 16:31:50 +0000
commit93d9a365d2902f186abe62968df871102b2b5b7a (patch)
tree797da951e525976483dc863bd4ee868353f828c7
parent510dbcce34f09967759f452e24c29269821f563d (diff)
downloadgcc-93d9a365d2902f186abe62968df871102b2b5b7a.zip
gcc-93d9a365d2902f186abe62968df871102b2b5b7a.tar.gz
gcc-93d9a365d2902f186abe62968df871102b2b5b7a.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h19
-rw-r--r--libstdc++-v3/include/bits/stl_bvector.h26
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/bool/swap.cc59
4 files changed, 107 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 5f3f3cd..cf6d913 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+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>
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index a002461..4e6e0f4 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1,7 +1,7 @@
// 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
@@ -74,6 +74,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
{
_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.
@@ -102,6 +103,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
swap(*__a, *__b);
}
};
+#endif
/**
* @brief Swaps the contents of two iterators.
@@ -117,16 +119,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
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,
@@ -140,6 +144,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __are_same<_ValueType1&, _ReferenceType1>::__value
&& __are_same<_ValueType2&, _ReferenceType2>::__value>::
iter_swap(__a, __b);
+#else
+ swap(*__a, *__b);
+#endif
}
/**
diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index ec3f83d..dfa0b32 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -108,6 +108,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ *_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>
{
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/swap.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/swap.cc
new file mode 100644
index 0000000..04aa0db
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/swap.cc
@@ -0,0 +1,59 @@
+// { 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;
+}