Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Refactor default constructor SFINAE in pair and tuple.
Browse files Browse the repository at this point in the history
Refactor the  recent implicit default constructor changes to match the
existing SFINAE style.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@373263 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
EricWF committed Sep 30, 2019
1 parent 9637883 commit 8ef0e6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 44 deletions.
5 changes: 3 additions & 2 deletions include/__tuple
Expand Up @@ -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 <class ...>
static constexpr bool __enable_default() { return false; }

static constexpr bool __enable_explicit_default() { return false; }
static constexpr bool __enable_implicit_default() { return false; }
template <class ...>
static constexpr bool __enable_explicit() { return false; }
template <class ...>
Expand Down
45 changes: 17 additions & 28 deletions include/tuple
Expand Up @@ -499,23 +499,18 @@ class _LIBCPP_TEMPLATE_VIS tuple
template <class _Dummy>
struct _CheckArgsConstructor<true, _Dummy>
{
template <class ..._Args>
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 <int&...>
static constexpr bool __enable_implicit_default() {
return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
}

template <int&...>
static constexpr bool __enable_explicit_default() {
return
__all<is_default_constructible<_Tp>::value...>::value &&
!__enable_implicit_default< >();
}

template <class ..._Args>
struct __enable_explicit_default
: integral_constant<bool,
__all<is_default_constructible<_Args>::value...>::value &&
!__enable_implicit_default<_Args...>::value
>
{ };

template <class ..._Args>
static constexpr bool __enable_explicit() {
Expand Down Expand Up @@ -655,14 +650,14 @@ class _LIBCPP_TEMPLATE_VIS tuple
public:

template <bool _Dummy = true, _EnableIf<
_CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>::value
_CheckArgsConstructor<_Dummy>::__enable_implicit_default()
, void*> = nullptr>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
tuple()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}

template <bool _Dummy = true, _EnableIf<
_CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>::value
_CheckArgsConstructor<_Dummy>::__enable_explicit_default()
, void*> = nullptr>
explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
tuple()
Expand All @@ -671,11 +666,8 @@ public:
tuple(tuple const&) = default;
tuple(tuple&&) = default;

template <class _AllocArgT, class _Alloc, bool _Dummy = true, _EnableIf<
_And<
_IsSame<allocator_arg_t, _AllocArgT>,
typename _CheckArgsConstructor<_Dummy>::template __enable_implicit_default<_Tp...>
>::value
template <class _AllocArgT, class _Alloc, _EnableIf<
_CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
, void*> = nullptr
>
_LIBCPP_INLINE_VISIBILITY
Expand All @@ -685,11 +677,8 @@ public:
typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
__tuple_types<_Tp...>()) {}

template <class _AllocArgT, class _Alloc, bool _Dummy = true, _EnableIf<
_And<
_IsSame<allocator_arg_t, _AllocArgT>,
typename _CheckArgsConstructor<_Dummy>::template __enable_explicit_default<_Tp...>
>::value
template <class _AllocArgT, class _Alloc, _EnableIf<
_CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
, void*> = nullptr
>
explicit _LIBCPP_INLINE_VISIBILITY
Expand Down
23 changes: 9 additions & 14 deletions include/utility
Expand Up @@ -334,22 +334,17 @@ struct _LIBCPP_TEMPLATE_VIS pair
using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;

struct _CheckArgs {
template <class _U1, class _U2>
template <int&...>
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 <class _U1, class _U2>
template <int&...>
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 <class _U1, class _U2>
Expand Down Expand Up @@ -400,15 +395,15 @@ struct _LIBCPP_TEMPLATE_VIS pair
>::type;

template<bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::template __enable_explicit_default<_T1, _T2>()
_CheckArgsDep<_Dummy>::__enable_explicit_default()
> = false>
explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
is_nothrow_default_constructible<second_type>::value)
: first(), second() {}

template<bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::template __enable_implicit_default<_T1, _T2>()
_CheckArgsDep<_Dummy>::__enable_implicit_default()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
Expand Down

0 comments on commit 8ef0e6a

Please sign in to comment.