summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-12 21:19:58 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-12 21:19:58 +0000
commit03ff028945a51ed376f0039e586eb76da0f437dd (patch)
treef43c510143e6877bb163e4aefc633110dadaa085 /libstdc++-v3/include
parentd27f6194d4aaba6ce020f8508d8961a634bcec90 (diff)
downloadgcc-03ff028945a51ed376f0039e586eb76da0f437dd.tar.gz
libstdc++/68877 Reimplement std::__is_swappable
2016-01-12 Daniel Kruegler <daniel.kruegler@gmail.com> PR libstdc++/68877 * include/std/type_traits: Following N4511, reimplement __is_swappable and __is_nothrow_swappable. Move __is_swappable to namespace std, adjust callers. Use __is_nothrow_swappable in swap. * include/bits/move.h: Use __is_nothrow_swappable in swap. * testsuite/20_util/is_nothrow_swappable/value.cc: Extend; remove __is_swappable related tests. * testsuite/20_util/is_swappable/value.cc: New. * testsuite/20_util/is_swappable/requirements/ explicit_instantiation.cc: New. * testsuite/20_util/is_swappable/requirements/typedefs.cc: New. * testsuite/25_algorithms/swap/68877.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232296 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/move.h4
-rw-r--r--libstdc++-v3/include/std/type_traits66
2 files changed, 47 insertions, 23 deletions
diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index a9bcdca37c1..afcea2d8468 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -198,9 +198,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, size_t _Nm>
inline
#if __cplusplus >= 201103L
- typename enable_if<__is_swappable_impl::__is_swappable<_Tp>::value>::type
+ typename enable_if<__is_swappable<_Tp>::value>::type
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
- noexcept(noexcept(swap(*__a, *__b)))
+ noexcept(__is_nothrow_swappable<_Tp>::value)
#else
void
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 37f039bcfe1..3a2b546b22f 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -2587,12 +2587,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: true_type \
{ };
+ template <typename _Tp>
+ struct __is_swappable;
- namespace __is_swappable_impl {
- template <typename _Tp, typename=void>
- struct __is_swappable : public false_type
- { };
- }
+ template <typename _Tp>
+ struct __is_nothrow_swappable;
template<typename _Tp>
inline
@@ -2604,33 +2603,58 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, size_t _Nm>
inline
- typename enable_if<__is_swappable_impl::__is_swappable<_Tp>::value>::type
+ typename enable_if<__is_swappable<_Tp>::value>::type
swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
- noexcept(noexcept(swap(*__a, *__b)));
+ noexcept(__is_nothrow_swappable<_Tp>::value);
- namespace __is_swappable_impl {
+ namespace __swappable_details {
using std::swap;
- template <typename _Tp>
- struct __is_swappable<_Tp, __void_t<decltype(swap(declval<_Tp&>(),
- declval<_Tp&>()))>>
- : public true_type
- { };
+ struct __do_is_swappable_impl
+ {
+ template<typename _Tp, typename
+ = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))>
+ static true_type __test(int);
+
+ template<typename>
+ static false_type __test(...);
+ };
+
+ struct __do_is_nothrow_swappable_impl
+ {
+ template<typename _Tp>
+ static __bool_constant<
+ noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))
+ > __test(int);
+
+ template<typename>
+ static false_type __test(...);
+ };
+
}
- template <bool, typename _Tp>
+ template<typename _Tp>
+ struct __is_swappable_impl
+ : public __swappable_details::__do_is_swappable_impl
+ {
+ typedef decltype(__test<_Tp>(0)) type;
+ };
+
+ template<typename _Tp>
struct __is_nothrow_swappable_impl
- : public __bool_constant<noexcept(swap(declval<_Tp&>(), declval<_Tp&>()))>
- { };
+ : public __swappable_details::__do_is_nothrow_swappable_impl
+ {
+ typedef decltype(__test<_Tp>(0)) type;
+ };
- template <typename _Tp>
- struct __is_nothrow_swappable_impl<false, _Tp> : public false_type
+ template<typename _Tp>
+ struct __is_swappable
+ : public __is_swappable_impl<_Tp>::type
{ };
- template <typename _Tp>
+ template<typename _Tp>
struct __is_nothrow_swappable
- : public __is_nothrow_swappable_impl<
- __is_swappable_impl::__is_swappable<_Tp>::value, _Tp>
+ : public __is_nothrow_swappable_impl<_Tp>::type
{ };
_GLIBCXX_END_NAMESPACE_VERSION