Skip to content

Commit

Permalink
<utility>: Privatize pair's internal non-Standard constructor (#4979
Browse files Browse the repository at this point in the history
)
  • Loading branch information
frederick-vs-ja authored Sep 28, 2024
1 parent 1c3e0d6 commit bbe8b6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 6 additions & 5 deletions stl/inc/utility
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ struct pair { // store a pair of values
}
#endif // _HAS_CXX23

template <class _Tuple1, class _Tuple2, size_t... _Indices1, size_t... _Indices2>
constexpr pair(_Tuple1& _Val1, _Tuple2& _Val2, index_sequence<_Indices1...>, index_sequence<_Indices2...>)
: first(_STD _Tuple_get<_Indices1>(_STD move(_Val1))...),
second(_STD _Tuple_get<_Indices2>(_STD move(_Val2))...) {}

template <class... _Types1, class... _Types2>
_CONSTEXPR20 pair(piecewise_construct_t, tuple<_Types1...> _Val1, tuple<_Types2...> _Val2)
: pair(_Val1, _Val2, index_sequence_for<_Types1...>{}, index_sequence_for<_Types2...>{}) {}
Expand Down Expand Up @@ -466,6 +461,12 @@ struct pair { // store a pair of values

_Ty1 first; // the first stored value
_Ty2 second; // the second stored value

private:
template <class _Tuple1, class _Tuple2, size_t... _Indices1, size_t... _Indices2>
constexpr pair(_Tuple1& _Val1, _Tuple2& _Val2, index_sequence<_Indices1...>, index_sequence<_Indices2...>)
: first(_STD _Tuple_get<_Indices1>(_STD move(_Val1))...),
second(_STD _Tuple_get<_Indices2>(_STD move(_Val2))...) {}
};

#if _HAS_CXX17
Expand Down
7 changes: 7 additions & 0 deletions tests/std/tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@ STATIC_ASSERT(!is_constructible_v<tuple<A>, allocator_arg_t, allocator<int>, pai
STATIC_ASSERT(is_constructible_v<tuple<A, A>, allocator_arg_t, allocator<int>, pair<Ex, Ex>>);
STATIC_ASSERT(!is_constructible_v<tuple<A, A, A>, allocator_arg_t, allocator<int>, pair<Ex, Ex>>);

// Also test that the internal constructor used for the piecewise_construct_t constructor of pair is not public.
STATIC_ASSERT(!is_constructible_v<pair<int, int>, tuple<>&, tuple<>&, make_index_sequence<0>, make_index_sequence<0>>);
STATIC_ASSERT(
!is_constructible_v<pair<int, int>, tuple<int>&, tuple<>&, make_index_sequence<1>, make_index_sequence<0>>);
STATIC_ASSERT(
!is_constructible_v<pair<int, int>, tuple<int>&, tuple<int>&, make_index_sequence<1>, make_index_sequence<1>>);


pair<int, int> func1() {
const int x = 17;
Expand Down

0 comments on commit bbe8b6b

Please sign in to comment.