aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Jefferson <caj@cs.york.ac.uk>2004-10-05 10:28:17 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2004-10-05 10:28:17 +0000
commit575665ff649eb2aac87bad3904b795c988077f30 (patch)
tree529c9760906ca57e7255036f5b9e86c9f2fb7bed
parent88a6ecb6f2950f8e6644bddc508b2e7ccaf53b06 (diff)
downloadgcc-575665ff649eb2aac87bad3904b795c988077f30.zip
gcc-575665ff649eb2aac87bad3904b795c988077f30.tar.gz
gcc-575665ff649eb2aac87bad3904b795c988077f30.tar.bz2
stl_algobase.h (iter_swap): delegate to swap via __iter_swap when iterator's value_types are equal.
2004-10-05 Christopher Jefferson <caj@cs.york.ac.uk> * include/bits/stl_algobase.h (iter_swap): delegate to swap via __iter_swap when iterator's value_types are equal. (struct __iter_swap): New. From-SVN: r88549
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h78
2 files changed, 59 insertions, 25 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 834f0b1..7dd6e7e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-05 Christopher Jefferson <caj@cs.york.ac.uk>
+
+ * include/bits/stl_algobase.h (iter_swap): delegate to swap via
+ __iter_swap when iterator's value_types are equal.
+ (struct __iter_swap): New.
+
2004-10-04 Benjamin Kosnik <bkoz@redhat.com>
* configure.ac (libtool_VERSION): To 6:3:0.
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index f3f20e6..6257890 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -77,6 +77,57 @@
namespace std
{
+
+ /**
+ * @brief Swaps two values.
+ * @param a A thing of arbitrary type.
+ * @param b Another thing of arbitrary type.
+ * @return Nothing.
+ *
+ * This is the simple classic generic implementation. It will work on
+ * any type which has a copy constructor and an assignment operator.
+ */
+ template<typename _Tp>
+ inline void
+ swap(_Tp& __a, _Tp& __b)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
+
+ const _Tp __tmp = __a;
+ __a = __b;
+ __b = __tmp;
+ }
+
+ // 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.
+ template<bool _BoolType>
+ struct __iter_swap
+ {
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
+ static void
+ iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
+ {
+ typedef typename iterator_traits<_ForwardIterator1>::value_type
+ _ValueType1;
+ const _ValueType1 __tmp = *__a;
+ *__a = *__b;
+ *__b = __tmp;
+ }
+ };
+
+ template<>
+ struct __iter_swap<true>
+ {
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
+ static void
+ iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
+ {
+ swap(*__a, *__b);
+ }
+ };
+
/**
* @brief Swaps the contents of two iterators.
* @param a An iterator.
@@ -104,31 +155,8 @@ namespace std
_ValueType2>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
_ValueType1>)
-
- const _ValueType1 __tmp = *__a;
- *__a = *__b;
- *__b = __tmp;
- }
-
- /**
- * @brief Swaps two values.
- * @param a A thing of arbitrary type.
- * @param b Another thing of arbitrary type.
- * @return Nothing.
- *
- * This is the simple classic generic implementation. It will work on
- * any type which has a copy constructor and an assignment operator.
- */
- template<typename _Tp>
- inline void
- swap(_Tp& __a, _Tp& __b)
- {
- // concept requirements
- __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
-
- const _Tp __tmp = __a;
- __a = __b;
- __b = __tmp;
+ std::__iter_swap<__are_same<_ValueType1, _ValueType2>::_M_type>::
+ iter_swap(__a, __b);
}
#undef min