From c8ad8686ac072fb35862f4d5e09cb1ab91a15a8e Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 30 Sep 2019 20:55:30 +0000 Subject: [PATCH] Refactor default constructor SFINAE in pair and tuple. Refactor the recent implicit default constructor changes to match the existing SFINAE style. llvm-svn: 373263 --- libcxx/include/__tuple | 5 +++-- libcxx/include/tuple | 45 +++++++++++++++++---------------------------- libcxx/include/utility | 23 +++++++++-------------- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/libcxx/include/__tuple b/libcxx/include/__tuple index 196f3c2..4da9ec5 100644 --- a/libcxx/include/__tuple +++ b/libcxx/include/__tuple @@ -477,8 +477,9 @@ using __tuple_like_with_size _LIBCPP_NODEBUG_TYPE = __tuple_like_with_size_imp< >; struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { - template - static constexpr bool __enable_default() { return false; } + + static constexpr bool __enable_explicit_default() { return false; } + static constexpr bool __enable_implicit_default() { return false; } template static constexpr bool __enable_explicit() { return false; } template diff --git a/libcxx/include/tuple b/libcxx/include/tuple index c4cd3bc..e93824f 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -499,23 +499,18 @@ class _LIBCPP_TEMPLATE_VIS tuple template struct _CheckArgsConstructor { - template - struct __enable_implicit_default - // In C++03, there's no way to implement the resolution of LWG2510. -#ifdef _LIBCPP_CXX03_LANG - : true_type -#else - : __all<__is_implicitly_default_constructible<_Args>::value...> -#endif - { }; + template + static constexpr bool __enable_implicit_default() { + return __all<__is_implicitly_default_constructible<_Tp>::value... >::value; + } + + template + static constexpr bool __enable_explicit_default() { + return + __all::value...>::value && + !__enable_implicit_default< >(); + } - template - struct __enable_explicit_default - : integral_constant::value...>::value && - !__enable_implicit_default<_Args...>::value - > - { }; template static constexpr bool __enable_explicit() { @@ -655,14 +650,14 @@ class _LIBCPP_TEMPLATE_VIS tuple public: template ::template __enable_implicit_default<_Tp...>::value + _CheckArgsConstructor<_Dummy>::__enable_implicit_default() , void*> = nullptr> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR tuple() _NOEXCEPT_(__all::value...>::value) {} template ::template __enable_explicit_default<_Tp...>::value + _CheckArgsConstructor<_Dummy>::__enable_explicit_default() , void*> = nullptr> explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR tuple() @@ -671,11 +666,8 @@ public: tuple(tuple const&) = default; tuple(tuple&&) = default; - template , - typename _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...> - >::value + template ::value >::__enable_implicit_default() , void*> = nullptr > _LIBCPP_INLINE_VISIBILITY @@ -685,11 +677,8 @@ public: typename __make_tuple_indices::type(), __tuple_types<_Tp...>()) {} - template , - typename _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...> - >::value + template ::value>::__enable_explicit_default() , void*> = nullptr > explicit _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/include/utility b/libcxx/include/utility index c90d049..7ac322b 100644 --- a/libcxx/include/utility +++ b/libcxx/include/utility @@ -334,22 +334,17 @@ struct _LIBCPP_TEMPLATE_VIS pair using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type; struct _CheckArgs { - template + template static constexpr bool __enable_explicit_default() { - return is_default_constructible<_U1>::value - && is_default_constructible<_U2>::value - && !__enable_implicit_default<_U1, _U2>(); + return is_default_constructible<_T1>::value + && is_default_constructible<_T2>::value + && !__enable_implicit_default<>(); } - template + template static constexpr bool __enable_implicit_default() { - // In C++03, there's no way to implement the resolution of LWG2510. -#ifdef _LIBCPP_CXX03_LANG - return true; -#else - return __is_implicitly_default_constructible<_U1>::value - && __is_implicitly_default_constructible<_U2>::value; -#endif + return __is_implicitly_default_constructible<_T1>::value + && __is_implicitly_default_constructible<_T2>::value; } template @@ -400,7 +395,7 @@ struct _LIBCPP_TEMPLATE_VIS pair >::type; template::template __enable_explicit_default<_T1, _T2>() + _CheckArgsDep<_Dummy>::__enable_explicit_default() > = false> explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() _NOEXCEPT_(is_nothrow_default_constructible::value && @@ -408,7 +403,7 @@ struct _LIBCPP_TEMPLATE_VIS pair : first(), second() {} template::template __enable_implicit_default<_T1, _T2>() + _CheckArgsDep<_Dummy>::__enable_implicit_default() > = false> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() _NOEXCEPT_(is_nothrow_default_constructible::value && -- 2.7.4