From 598983d7a96e19bb84200bed6d8c7e1968123dbe Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Tue, 1 Feb 2022 21:36:50 +0100 Subject: [PATCH] [libc++][P2321R2] Add specializations of basic_common_reference and common_type for pair Add specializations of basic_common_reference and common_type for pair Reviewed By: Quuxplusone, Mordante, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D117506 --- libcxx/docs/Status/ZipProjects.csv | 4 ++-- libcxx/include/__utility/pair.h | 18 ++++++++++++++++- libcxx/include/utility | 6 ++++++ .../common_reference.compile.pass.cpp | 20 +++++++++++++++++++ .../meta.trans.other/common_type.pass.cpp | 20 ++++++++++++++++--- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/libcxx/docs/Status/ZipProjects.csv b/libcxx/docs/Status/ZipProjects.csv index 4990d6b3e10f9..30fd859293e50 100644 --- a/libcxx/docs/Status/ZipProjects.csv +++ b/libcxx/docs/Status/ZipProjects.csv @@ -1,7 +1,7 @@ Section,Description,Dependencies,Assignee,Complete -| `[tuple.syn] `_, "`[tuple] basic_common_reference, common_type `_", None, Nikolas Klauser, |In Progress| +| `[tuple.syn] `_, "`[tuple] basic_common_reference, common_type `_", None, Nikolas Klauser, |Complete| | `[tuple.tuple] `_, "`[tuple] constructor, assignment and swap overloads `_", None, Nikolas Klauser, |In Progress| -| `[utility.syn] `_, "[pair] basic_common_reference, common_type", None, Nikolas Klauser, |Not Started| +| `[utility.syn] `_, "[pair] basic_common_reference, common_type", None, Nikolas Klauser, |Complete| | `[pairs.pair] `_, "[pair] constructor, assignment and swap overloads", None, Nikolas Klauser, |Not Started| "| `[memory.syn] `_ | `[allocator.uses.construction] `_", "[pair] uses_allocator_construction_args overloads", None, Unassigned, |Not Started| diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h index f1114696884ac..2c8593ac3b66c 100644 --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -315,7 +315,7 @@ struct _LIBCPP_TEMPLATE_VIS pair #endif }; -#if _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER > 14 template pair(_T1, _T2) -> pair<_T1, _T2>; #endif @@ -389,6 +389,22 @@ operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) +#if _LIBCPP_STD_VER > 20 +template class _TQual, template class _UQual> + requires requires { typename pair, _UQual<_U1>>, + common_reference_t<_TQual<_T2>, _UQual<_U2>>>; } +struct basic_common_reference, pair<_U1, _U2>, _TQual, _UQual> { + using type = pair, _UQual<_U1>>, + common_reference_t<_TQual<_T2>, _UQual<_U2>>>; +}; + +template + requires requires { typename pair, common_type_t<_T2, _U2>>; } +struct common_type, pair<_U1, _U2>> { + using type = pair, common_type_t<_T2, _U2>>; +}; +#endif + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if diff --git a/libcxx/include/utility b/libcxx/include/utility index 9dd7905516a86..db68181a67a91 100644 --- a/libcxx/include/utility +++ b/libcxx/include/utility @@ -95,6 +95,12 @@ struct pair is_nothrow_swappable_v); // constexpr in C++20 }; +template class TQual, template class UQual> +struct basic_common_reference, pair, TQual, UQual>; // since C++23 + +template +struct common_type, pair>; // since C++23 + template pair(T1, T2) -> pair; template bool operator==(const pair&, const pair&); // constexpr in C++14 diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_reference.compile.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_reference.compile.pass.cpp index 17421c17f1dee..135f933ebbcb9 100644 --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_reference.compile.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_reference.compile.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "test_macros.h" @@ -197,6 +198,25 @@ struct std::basic_common_reference, TQual, UQual> { static_assert(std::is_same_v,std::tuple>, std::tuple>); + +static_assert(std::is_same_v>, + std::pair>); +static_assert(std::is_same_v, std::pair>, + std::pair>); +static_assert(std::is_same_v, std::pair>, + std::pair>); +static_assert(std::is_same_v, std::pair>, + std::pair>); +static_assert(std::is_same_v, std::pair>, + std::pair>); +static_assert(!has_type, + std::pair>>); + +static_assert(std::is_same_v, std::pair>, std::pair>); +static_assert(std::is_same_v, std::pair>, std::pair>); +static_assert(!has_type, std::pair>>); +static_assert(!has_type, std::pair>>); +static_assert(!has_type, int, X2>>); #endif int main(int, char**) { return 0; } diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp index 901443a2c4bd2..2842d9835d408 100644 --- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "test_macros.h" @@ -234,11 +235,11 @@ void test_bullet_three_four() { static_assert(std::is_same_v, double>, double>, ""); static_assert(std::is_same_v, double>, double>, ""); static_assert(std::is_same_v, double>, double>, ""); - + static_assert(std::is_same_v, const double>, double>, ""); static_assert(std::is_same_v, volatile double>, double>, ""); static_assert(std::is_same_v, const volatile double>, double>, ""); - + static_assert(std::is_same_v&, double>, double>, ""); static_assert(std::is_same_v, double&>, double>, ""); #endif @@ -359,7 +360,20 @@ int main(int, char**) static_assert(std::is_same_v>, std::tuple>); static_assert(std::is_same_v, std::tuple>, std::tuple>); - static_assert(std::is_same_v,std::tuple>, std::tuple>); + static_assert(std::is_same_v,std::tuple>, std::tuple>); + + static_assert(std::is_same_v>, std::pair>); + static_assert(std::is_same_v, std::pair>, std::pair>); + static_assert(std::is_same_v, + std::pair>, + std::pair>); + + static_assert(std::is_same_v>, std::pair>); + static_assert(std::is_same_v, + std::pair>, + std::pair>); + + static_assert(std::is_same_v,std::tuple>, std::tuple>); #endif return 0;