Skip to content

Commit

Permalink
Revert "[libc++][NFC] Simplify pair a bit" (#97003)
Browse files Browse the repository at this point in the history
Reverts #96165

The change broke code like

  #include <utility>
  #include <vector>

  struct Test {
    std::vector<std::pair<int, Test>> v;
  };

  std::pair<int, Test> p;

under `-std=c++20`, apparently by triggering certain template
evaluations too eagerly.
  • Loading branch information
jyknight authored Jun 28, 2024
1 parent 5997ebd commit 5e1de27
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions libcxx/include/__utility/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <__fwd/array.h>
#include <__fwd/pair.h>
#include <__fwd/tuple.h>
#include <__tuple/sfinae_helpers.h>
#include <__tuple/tuple_element.h>
#include <__tuple/tuple_indices.h>
#include <__tuple/tuple_like_no_subrange.h>
#include <__tuple/tuple_size.h>
Expand Down Expand Up @@ -128,15 +130,19 @@ struct _LIBCPP_TEMPLATE_VIS pair
}
};

template <bool _Dummy = true, __enable_if_t<_Dummy && _CheckArgs::__enable_default(), int> = 0>
explicit(!_CheckArgs::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
template <bool _MaybeEnable>
using _CheckArgsDep _LIBCPP_NODEBUG =
typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;

template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>
explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
is_nothrow_default_constructible<first_type>::value && is_nothrow_default_constructible<second_type>::value)
: first(), second() {}

template <bool _Dummy = true,
__enable_if_t<_Dummy && _CheckArgs::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
template <bool _Dummy = true,
__enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
_LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_T1 const&, _T2 const&>())
_LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep<_Dummy>::template __is_implicit<_T1 const&, _T2 const&>())
pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value &&
is_nothrow_copy_constructible<second_type>::value)
: first(__t1), second(__t2) {}
Expand Down

0 comments on commit 5e1de27

Please sign in to comment.