[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
This commit is contained in:
Nikolas Klauser
2022-02-01 21:36:50 +01:00
parent 11cf807796
commit 598983d7a9
5 changed files with 62 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
Section,Description,Dependencies,Assignee,Complete
| `[tuple.syn] <https://wg21.link/tuple.syn>`_, "`[tuple] basic_common_reference, common_type <https://reviews.llvm.org/D116538>`_", None, Nikolas Klauser, |In Progress|
| `[tuple.syn] <https://wg21.link/tuple.syn>`_, "`[tuple] basic_common_reference, common_type <https://reviews.llvm.org/D116538>`_", None, Nikolas Klauser, |Complete|
| `[tuple.tuple] <https://wg21.link/tuple.tuple>`_, "`[tuple] constructor, assignment and swap overloads <https://reviews.llvm.org/D116621>`_", None, Nikolas Klauser, |In Progress|
| `[utility.syn] <https://wg21.link/utility.syn>`_, "[pair] basic_common_reference, common_type", None, Nikolas Klauser, |Not Started|
| `[utility.syn] <https://wg21.link/utility.syn>`_, "[pair] basic_common_reference, common_type", None, Nikolas Klauser, |Complete|
| `[pairs.pair] <https://wg21.link/pairs.pair>`_, "[pair] constructor, assignment and swap overloads", None, Nikolas Klauser, |Not Started|
"| `[memory.syn] <https://wg21.link/memory.syn>`_
| `[allocator.uses.construction] <https://wg21.link/allocator.uses.construction>`_", "[pair] uses_allocator_construction_args overloads", None, Unassigned, |Not Started|
1 Section Description Dependencies Assignee Complete
2 | `[tuple.syn] <https://wg21.link/tuple.syn>`_ `[tuple] basic_common_reference, common_type <https://reviews.llvm.org/D116538>`_ None Nikolas Klauser |In Progress| |Complete|
3 | `[tuple.tuple] <https://wg21.link/tuple.tuple>`_ `[tuple] constructor, assignment and swap overloads <https://reviews.llvm.org/D116621>`_ None Nikolas Klauser |In Progress|
4 | `[utility.syn] <https://wg21.link/utility.syn>`_ [pair] basic_common_reference, common_type None Nikolas Klauser |Not Started| |Complete|
5 | `[pairs.pair] <https://wg21.link/pairs.pair>`_ [pair] constructor, assignment and swap overloads None Nikolas Klauser |Not Started|
6 | `[memory.syn] <https://wg21.link/memory.syn>`_ | `[allocator.uses.construction] <https://wg21.link/allocator.uses.construction>`_ [pair] uses_allocator_construction_args overloads None Unassigned |Not Started|
7 | `[vector.bool] <https://wg21.link/vector.bool>`_ [vector<bool>::reference] add const operator= overload None Nikolas Klauser |Not Started|

View File

@@ -315,7 +315,7 @@ private:
#endif
};
#if _LIBCPP_STD_VER >= 17
#if _LIBCPP_STD_VER > 14
template<class _T1, class _T2>
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 _T1, class _T2, class _U1, class _U2, template<class> class _TQual, template<class> class _UQual>
requires requires { typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>,
common_reference_t<_TQual<_T2>, _UQual<_U2>>>; }
struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {
using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>,
common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
};
template <class _T1, class _T2, class _U1, class _U2>
requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }
struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {
using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
};
#endif
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename enable_if

View File

@@ -95,6 +95,12 @@ struct pair
is_nothrow_swappable_v<T2>); // constexpr in C++20
};
template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>
struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23
template<class T1, class T2, class U1, class U2>
struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23
template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14

View File

@@ -15,6 +15,7 @@
#include <tuple>
#include <type_traits>
#include <utility>
#include "test_macros.h"
@@ -197,6 +198,25 @@ struct std::basic_common_reference<A, std::tuple<B>, TQual, UQual> {
static_assert(std::is_same_v<std::common_reference_t<A, std::tuple<B>,std::tuple<D>>, std::tuple<B>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int, int>>,
std::pair<int, int>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int, long>, std::pair<long, int>>,
std::pair<long, long>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int&, const int&>, std::pair<const int&, int>>,
std::pair<const int&, int>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int&, volatile int&>, std::pair<volatile int&, int>>,
std::pair<volatile int&, int>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int&, const volatile int&>, std::pair<const volatile int&, int>>,
std::pair<const volatile int&, int>>);
static_assert(!has_type<std::common_reference_t<std::pair<const int&, volatile int&>,
std::pair<volatile int&, const int&>>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int, X2>, std::pair<int, Y2>>, std::pair<int, Z2>>);
static_assert(std::is_same_v<std::common_reference_t<std::pair<int, X2>, std::pair<int, Y2>>, std::pair<int, Z2>>);
static_assert(!has_type<std::common_reference<std::pair<int, const X2>, std::pair<float, const Z2>>>);
static_assert(!has_type<std::common_reference<std::pair<int, X2>, std::pair<float, Z2>>>);
static_assert(!has_type<std::common_reference<std::pair<int, X2>, int, X2>>);
#endif
int main(int, char**) { return 0; }

View File

@@ -14,6 +14,7 @@
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>
#include "test_macros.h"
@@ -234,11 +235,11 @@ void test_bullet_three_four() {
static_assert(std::is_same_v<std::common_type_t<const bad_reference_wrapper<double>, double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<volatile bad_reference_wrapper<double>, double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<const volatile bad_reference_wrapper<double>, double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<bad_reference_wrapper<double>, const double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<bad_reference_wrapper<double>, volatile double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<bad_reference_wrapper<double>, const volatile double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<bad_reference_wrapper<double>&, double>, double>, "");
static_assert(std::is_same_v<std::common_type_t<bad_reference_wrapper<double>, double&>, double>, "");
#endif
@@ -359,7 +360,20 @@ int main(int, char**)
static_assert(std::is_same_v<std::common_type_t<std::tuple<const int&>>, std::tuple<int>>);
static_assert(std::is_same_v<std::common_type_t<std::tuple<const volatile int&>, std::tuple<const volatile long&>>, std::tuple<long>>);
static_assert(std::is_same_v<std::common_reference_t<A, std::tuple<B>,std::tuple<C>>, std::tuple<B>>);
static_assert(std::is_same_v<std::common_type_t<A, std::tuple<B>,std::tuple<C>>, std::tuple<B>>);
static_assert(std::is_same_v<std::common_type_t<std::pair<int, int>>, std::pair<int, int>>);
static_assert(std::is_same_v<std::common_type_t<std::pair<int, long>, std::pair<long, int>>, std::pair<long, long>>);
static_assert(std::is_same_v<std::common_type_t<std::pair<const int, const long>,
std::pair<const int, const long>>,
std::pair<int, long>>);
static_assert(std::is_same_v<std::common_type_t<std::pair<const int&, const long&>>, std::pair<int, long>>);
static_assert(std::is_same_v<std::common_type_t<std::pair<const volatile int&, const volatile long&>,
std::pair<const volatile long&, const volatile int&>>,
std::pair<long, long>>);
static_assert(std::is_same_v<std::common_type_t<A, std::tuple<B>,std::tuple<C>>, std::tuple<B>>);
#endif
return 0;