Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<utility>: Privatize pair's internal non-Standard constructor #4979

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions stl/inc/utility
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,10 @@ 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...>{}) {}

pair& operator=(const volatile pair&) = delete;

template <class _Myself = pair,
enable_if_t<conjunction_v<_Is_copy_assignable_no_precondition_check<typename _Myself::first_type>,
_Is_copy_assignable_no_precondition_check<typename _Myself::second_type>>,
Expand Down Expand Up @@ -466,6 +459,14 @@ 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))...) {}

pair& operator=(const volatile pair&) = delete;
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
};

#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