@@ -275,6 +275,14 @@ struct pair { // store a pair of values
275275 is_nothrow_constructible_v<_Ty1, _Other1> && is_nothrow_constructible_v<_Ty2, _Other2>) // strengthened
276276 : first(_STD forward<_Other1>(_Val1)), second(_STD forward<_Other2>(_Val2)) {
277277 }
278+ #ifdef __cpp_lib_reference_from_temporary
279+ template <class _Other1 = _Ty1, class _Other2 = _Ty2,
280+ enable_if_t<conjunction_v<is_constructible<_Ty1, _Other1>, is_constructible<_Ty2, _Other2>>, int> = 0>
281+ requires reference_constructs_from_temporary_v<_Ty1, _Other1&&>
282+ || reference_constructs_from_temporary_v<_Ty2, _Other2&&>
283+ explicit(!conjunction_v<is_convertible<_Other1, _Ty1>, is_convertible<_Other2, _Ty2>>)
284+ pair(_Other1&&, _Other2&&) = delete;
285+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
278286
279287 pair(const pair&) = default;
280288 pair(pair&&) = default;
@@ -286,6 +294,14 @@ struct pair { // store a pair of values
286294 pair(pair<_Other1, _Other2>& _Right) noexcept(
287295 is_nothrow_constructible_v<_Ty1, _Other1&> && is_nothrow_constructible_v<_Ty2, _Other2&>) // strengthened
288296 : first(_Right.first), second(_Right.second) {}
297+ #ifdef __cpp_lib_reference_from_temporary
298+ template <class _Other1, class _Other2>
299+ requires is_constructible_v<_Ty1, _Other1&> && is_constructible_v<_Ty2, _Other2&>
300+ && (reference_constructs_from_temporary_v<_Ty1, _Other1&>
301+ || reference_constructs_from_temporary_v<_Ty2, _Other2&>)
302+ explicit(!conjunction_v<is_convertible<_Other1&, _Ty1>, is_convertible<_Other2&, _Ty2>>)
303+ pair(pair<_Other1, _Other2>&) = delete;
304+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
289305#endif // _HAS_CXX23
290306
291307 template <class _Other1, class _Other2,
@@ -296,13 +312,30 @@ struct pair { // store a pair of values
296312 noexcept(is_nothrow_constructible_v<_Ty1, const _Other1&>
297313 && is_nothrow_constructible_v<_Ty2, const _Other2&>) // strengthened
298314 : first(_Right.first), second(_Right.second) {}
315+ #ifdef __cpp_lib_reference_from_temporary
316+ template <class _Other1, class _Other2,
317+ enable_if_t<conjunction_v<is_constructible<_Ty1, const _Other1&>, is_constructible<_Ty2, const _Other2&>>,
318+ int> = 0>
319+ requires reference_constructs_from_temporary_v<_Ty1, const _Other1&>
320+ || reference_constructs_from_temporary_v<_Ty2, const _Other2&>
321+ explicit(!conjunction_v<is_convertible<const _Other1&, _Ty1>, is_convertible<const _Other2&, _Ty2>>)
322+ pair(const pair<_Other1, _Other2>&) = delete;
323+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
299324
300325 template <class _Other1, class _Other2,
301326 enable_if_t<conjunction_v<is_constructible<_Ty1, _Other1>, is_constructible<_Ty2, _Other2>>, int> = 0>
302327 constexpr explicit(!conjunction_v<is_convertible<_Other1, _Ty1>, is_convertible<_Other2, _Ty2>>)
303328 pair(pair<_Other1, _Other2>&& _Right) noexcept(
304329 is_nothrow_constructible_v<_Ty1, _Other1> && is_nothrow_constructible_v<_Ty2, _Other2>) // strengthened
305330 : first(_STD forward<_Other1>(_Right.first)), second(_STD forward<_Other2>(_Right.second)) {}
331+ #ifdef __cpp_lib_reference_from_temporary
332+ template <class _Other1, class _Other2,
333+ enable_if_t<conjunction_v<is_constructible<_Ty1, _Other1>, is_constructible<_Ty2, _Other2>>, int> = 0>
334+ requires reference_constructs_from_temporary_v<_Ty1, _Other1&&>
335+ || reference_constructs_from_temporary_v<_Ty2, _Other2&&>
336+ explicit(!conjunction_v<is_convertible<_Other1, _Ty1>, is_convertible<_Other2, _Ty2>>)
337+ pair(pair<_Other1, _Other2>&&) = delete;
338+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
306339
307340#if _HAS_CXX23
308341 template <class _Other1, class _Other2>
@@ -312,6 +345,14 @@ struct pair { // store a pair of values
312345 noexcept(is_nothrow_constructible_v<_Ty1, const _Other1>
313346 && is_nothrow_constructible_v<_Ty2, const _Other2>) // strengthened
314347 : first(_STD forward<const _Other1>(_Right.first)), second(_STD forward<const _Other2>(_Right.second)) {}
348+ #ifdef __cpp_lib_reference_from_temporary
349+ template <class _Other1, class _Other2>
350+ requires is_constructible_v<_Ty1, const _Other1> && is_constructible_v<_Ty2, const _Other2>
351+ && (reference_constructs_from_temporary_v<_Ty1, const _Other1 &&>
352+ || reference_constructs_from_temporary_v<_Ty2, const _Other2 &&>)
353+ explicit(!conjunction_v<is_convertible<const _Other1, _Ty1>, is_convertible<const _Other2, _Ty2>>)
354+ pair(const pair<_Other1, _Other2>&&) = delete;
355+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
315356
316357#ifdef __EDG__ // TRANSITION, VSO-1900279
317358 template <class _Other, enable_if_t<_Can_construct_from_pair_like<_Other, _Ty1, _Ty2>, int> = 0>
@@ -326,6 +367,15 @@ struct pair { // store a pair of values
326367 && is_nothrow_constructible_v<_Ty2, decltype(_STD get<1>(_STD declval<_Other>()))>) // strengthened
327368 : first(_STD get<0>(_STD forward<_Other>(_Right))), second(_STD get<1>(_STD forward<_Other>(_Right))) {
328369 }
370+ #ifdef __cpp_lib_reference_from_temporary
371+ template <_Pair_like_non_subrange _Other>
372+ requires conjunction_v<is_constructible<_Ty1, decltype(_STD get<0>(_STD declval<_Other>()))>,
373+ is_constructible<_Ty2, decltype(_STD get<1>(_STD declval<_Other>()))>>
374+ && (reference_constructs_from_temporary_v<_Ty1, decltype(_STD get<0>(_STD declval<_Other>()))>
375+ || reference_constructs_from_temporary_v<_Ty2, decltype(_STD get<1>(_STD declval<_Other>()))>)
376+ explicit(!conjunction_v<is_convertible<decltype(_STD get<0>(_STD declval<_Other>())), _Ty1>,
377+ is_convertible<decltype(_STD get<1>(_STD declval<_Other>())), _Ty2>>) pair(_Other&&) = delete;
378+ #endif // ^^^ defined(__cpp_lib_reference_from_temporary) ^^^
329379#endif // _HAS_CXX23
330380
331381 template <class... _Types1, class... _Types2>
0 commit comments