mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-11-27 05:40:48 +00:00
[libcxx] Implement P0318: unwrap_ref_decay and unwrap_reference
Summary: This was voted into C++20 in San Diego. Note that there was a revision D0318R2 which did include unwrap_reference_t, but we mistakingly voted P0318R1 into the C++20 Working Draft (which does not include unwrap_reference_t). This patch implements D0318R2, which is what we'll end up with in the Working Draft once this mistake has been fixed. Reviewers: EricWF, mclow.lists Subscribers: christof, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D54485 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@348138 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a815a3f8cc
commit
604afd7688
@ -68,6 +68,11 @@ template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
|
||||
template <class T> void cref(const T&& t) = delete;
|
||||
template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
|
||||
|
||||
template <class T> struct unwrap_reference; // since C++20
|
||||
template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
|
||||
template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
|
||||
template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
|
||||
|
||||
template <class T> // <class T=void> in C++14
|
||||
struct plus : binary_function<T, T, T>
|
||||
{
|
||||
@ -2527,6 +2532,14 @@ private:
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 14
|
||||
|
||||
#if _LIBCPP_STD_VER > 17
|
||||
template <class _Tp>
|
||||
using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
|
||||
|
||||
template <class _Tp>
|
||||
using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
|
||||
#endif // > C++17
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_FUNCTIONAL
|
||||
|
@ -1078,30 +1078,12 @@ namespace {
|
||||
_LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_tuple_return_impl
|
||||
{
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_tuple_return_impl<reference_wrapper<_Tp> >
|
||||
{
|
||||
typedef _Tp& type;
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_tuple_return
|
||||
{
|
||||
typedef typename __make_tuple_return_impl<typename decay<_Tp>::type>::type type;
|
||||
};
|
||||
|
||||
template <class... _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
tuple<typename __make_tuple_return<_Tp>::type...>
|
||||
tuple<typename __unwrap_ref_decay<_Tp>::type...>
|
||||
make_tuple(_Tp&&... __t)
|
||||
{
|
||||
return tuple<typename __make_tuple_return<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
|
||||
return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
|
||||
}
|
||||
|
||||
template <class... _Tp>
|
||||
|
@ -616,32 +616,37 @@ swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
|
||||
__x.swap(__y);
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
struct __unwrap_reference { typedef _Tp type; };
|
||||
|
||||
template <class _Tp>
|
||||
struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _Tp& type; };
|
||||
|
||||
#if _LIBCPP_STD_VER > 17
|
||||
template <class _Tp>
|
||||
struct unwrap_reference : __unwrap_reference<_Tp> { };
|
||||
|
||||
template <class _Tp>
|
||||
struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { };
|
||||
#endif // > C++17
|
||||
|
||||
template <class _Tp>
|
||||
struct __unwrap_ref_decay
|
||||
#if _LIBCPP_STD_VER > 17
|
||||
: unwrap_ref_decay<_Tp>
|
||||
#else
|
||||
: __unwrap_reference<typename decay<_Tp>::type>
|
||||
#endif
|
||||
{ };
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_pair_return_impl
|
||||
{
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_pair_return_impl<reference_wrapper<_Tp>>
|
||||
{
|
||||
typedef _Tp& type;
|
||||
};
|
||||
|
||||
template <class _Tp>
|
||||
struct __make_pair_return
|
||||
{
|
||||
typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type;
|
||||
};
|
||||
|
||||
template <class _T1, class _T2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||
pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
|
||||
pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
|
||||
make_pair(_T1&& __t1, _T2&& __t2)
|
||||
{
|
||||
return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type>
|
||||
return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
|
||||
(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
//
|
||||
// template <class T>
|
||||
// struct unwrap_ref_decay;
|
||||
//
|
||||
// template <class T>
|
||||
// using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
|
||||
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
template <typename T, typename Result>
|
||||
void check() {
|
||||
static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, Result>);
|
||||
static_assert(std::is_same_v<typename std::unwrap_ref_decay<T>::type, std::unwrap_ref_decay_t<T>>);
|
||||
}
|
||||
|
||||
struct T { };
|
||||
|
||||
int main() {
|
||||
check<T, T>();
|
||||
check<T&, T>();
|
||||
check<T const, T>();
|
||||
check<T const&, T>();
|
||||
check<T*, T*>();
|
||||
check<T const*, T const*>();
|
||||
check<T[3], T*>();
|
||||
check<T const [3], T const*>();
|
||||
check<T (), T (*)()>();
|
||||
check<T (int) const, T (int) const>();
|
||||
check<T (int) &, T (int) &>();
|
||||
check<T (int) &&, T (int) &&>();
|
||||
|
||||
check<std::reference_wrapper<T>, T&>();
|
||||
check<std::reference_wrapper<T>&, T&>();
|
||||
check<std::reference_wrapper<T const>, T const&>();
|
||||
check<std::reference_wrapper<T const>&, T const&>();
|
||||
check<std::reference_wrapper<T*>, T*&>();
|
||||
check<std::reference_wrapper<T*>&, T*&>();
|
||||
check<std::reference_wrapper<T const*>, T const*&>();
|
||||
check<std::reference_wrapper<T const*>&, T const*&>();
|
||||
check<std::reference_wrapper<T[3]>, T (&)[3]>();
|
||||
check<std::reference_wrapper<T[3]>&, T (&)[3]>();
|
||||
check<std::reference_wrapper<T ()>, T (&)()>();
|
||||
check<std::reference_wrapper<T ()>&, T (&)()>();
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
//
|
||||
// template <class T>
|
||||
// struct unwrap_reference;
|
||||
//
|
||||
// template <class T>
|
||||
// using unwrap_reference_t = typename unwrap_reference<T>::type;
|
||||
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
template <typename T, typename Expected>
|
||||
void check_equal() {
|
||||
static_assert(std::is_same_v<typename std::unwrap_reference<T>::type, Expected>);
|
||||
static_assert(std::is_same_v<typename std::unwrap_reference<T>::type, std::unwrap_reference_t<T>>);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void check() {
|
||||
check_equal<T, T>();
|
||||
check_equal<T&, T&>();
|
||||
check_equal<T const, T const>();
|
||||
check_equal<T const&, T const&>();
|
||||
|
||||
check_equal<std::reference_wrapper<T>, T&>();
|
||||
check_equal<std::reference_wrapper<T const>, T const&>();
|
||||
}
|
||||
|
||||
struct T { };
|
||||
|
||||
int main() {
|
||||
check<T>();
|
||||
check<int>();
|
||||
check<float>();
|
||||
|
||||
check<T*>();
|
||||
check<int*>();
|
||||
check<float*>();
|
||||
}
|
@ -108,7 +108,7 @@
|
||||
<tr><td><a href="https://wg21.link/P1120R0">P1120R0</a></td><td>CWG</td><td>Consistency improvements for <=> and other comparison operators</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||
|
||||
<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0318R1">P0318R1</a></td><td>LWG</td><td>unwrap_ref_decay and unwrap_reference</td><td>San Diego</td><td><i> </i></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0318R1">P0318R1</a></td><td>LWG</td><td>unwrap_ref_decay and unwrap_reference</td><td>San Diego</td><td>Complete</td><td>8.0</td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0356R5">P0356R5</a></td><td>LWG</td><td>Simplified partial function application</td><td>San Diego</td><td><i> </i></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0357R3">P0357R3</a></td><td>LWG</td><td>reference_wrapper for incomplete types</td><td>San Diego</td><td><i> </i></td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/P0482R6">P0482R6</a></td><td>CWG</td><td>char8_t: A type for UTF-8 characters and strings</td><td>San Diego</td><td><i> </i></td><td></td></tr>
|
||||
|
Loading…
Reference in New Issue
Block a user