From aedcbf898b7136b3aa09f236240eb5f1f05e4b78 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 25 Jul 2016 02:36:42 +0000 Subject: Recommit r276548 - Make pair/tuples assignment operators SFINAE properly. I think I've solved issues with is_assignable and references to incomplete types. The updated patch adds tests for this case. llvm-svn: 276603 --- libcxx/include/tuple | 22 ++++++++++++++++++++++ libcxx/include/utility | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 12 deletions(-) (limited to 'libcxx/include') diff --git a/libcxx/include/tuple b/libcxx/include/tuple index 31613d2b94f..a68f115b68c 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -647,6 +647,9 @@ public: _LIBCPP_CONSTEXPR tuple() _NOEXCEPT_(__all::value...>::value) {} + tuple(tuple const&) = default; + tuple(tuple&&) = default; + template , @@ -885,6 +888,25 @@ public: tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + using _CanCopyAssign = __all::value...>; + using _CanMoveAssign = __all::value...>; + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t) + _NOEXCEPT_((__all::value...>::value)) + { + base_.operator=(__t.base_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t) + _NOEXCEPT_((__all::value...>::value)) + { + base_.operator=(static_cast(__t.base_)); + return *this; + } + template ::value + && is_copy_assignable<_T2>::value, + pair, __nat + >::type _CopyAssignT; + typedef typename conditional< + is_move_assignable<_T1>::value + && is_move_assignable<_T2>::value, + pair, __nat + >::type _MoveAssignT; +#else + typedef pair _CopyAssignT; +#endif + _LIBCPP_INLINE_VISIBILITY - pair& operator=(const pair& __p) + pair& operator=(_CopyAssignT const& __p) _NOEXCEPT_(is_nothrow_copy_assignable::value && is_nothrow_copy_assignable::value) { @@ -358,6 +373,18 @@ struct _LIBCPP_TYPE_VIS_ONLY pair return *this; } +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + pair& operator=(_MoveAssignT&& __p) + _NOEXCEPT_(is_nothrow_move_assignable::value && + is_nothrow_move_assignable::value) + { + first = _VSTD::forward(__p.first); + second = _VSTD::forward(__p.second); + return *this; + } +#endif + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template (__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} - _LIBCPP_INLINE_VISIBILITY - pair& - operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable::value && - is_nothrow_move_assignable::value) - { - first = _VSTD::forward(__p.first); - second = _VSTD::forward(__p.second); - return *this; - } -#ifndef _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_HAS_NO_VARIADICS template::value>::type> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -411,7 +429,7 @@ struct _LIBCPP_TYPE_VIS_ONLY pair {} template ::value>::type> + class = typename enable_if::type, pair>::value && __tuple_assignable<_Tuple, pair>::value>::type> _LIBCPP_INLINE_VISIBILITY pair& operator=(_Tuple&& __p) -- cgit v1.2.3