From: Jonathan Wakely Date: Thu, 3 May 2018 12:40:10 +0000 (+0100) Subject: Define std::remove_cvref and std::remove_cvref_t for C++2a X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6791489ee5214b0181aa22adc250cbbde1897a5c;p=gcc.git Define std::remove_cvref and std::remove_cvref_t for C++2a Also define __remove_cvref_t for internal use before C++2a. * include/std/any (any_cast): Use __remove_cvref_t. * include/std/tuple (__make_tuple): Likewise. * include/std/type_traits (__remove_cvref_t): Define. (__result_of_memobj, __result_of_memfun): Use __remove_cvref_t. [__cplusplus > 201703L] (remove_cvref, remove_cvref_t): Define. * include/std/variant (__erased_hash): Use __remove_cvref_t. From-SVN: r259887 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 69a9eeba469..692a46869fc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2018-05-03 Jonathan Wakely + + * include/std/any (any_cast): Use __remove_cvref_t. + * include/std/tuple (__make_tuple): Likewise. + * include/std/type_traits (__remove_cvref_t): Define. + (__result_of_memobj, __result_of_memfun): Use __remove_cvref_t. + [__cplusplus > 201703L] (remove_cvref, remove_cvref_t): Define. + * include/std/variant (__erased_hash): Use __remove_cvref_t. + 2018-05-02 François Dumont * include/bits/deque.tcc (deque<>::_M_assign_aux): Cast to void to diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index a37eb38d665..11b59d6d575 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -451,7 +451,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline _ValueType any_cast(const any& __any) { - using _Up = remove_cv_t>; + using _Up = __remove_cvref_t<_ValueType>; static_assert(any::__is_valid_cast<_ValueType>(), "Template argument must be a reference or CopyConstructible type"); static_assert(is_constructible_v<_ValueType, const _Up&>, @@ -477,7 +477,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline _ValueType any_cast(any& __any) { - using _Up = remove_cv_t>; + using _Up = __remove_cvref_t<_ValueType>; static_assert(any::__is_valid_cast<_ValueType>(), "Template argument must be a reference or CopyConstructible type"); static_assert(is_constructible_v<_ValueType, _Up&>, @@ -491,7 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline _ValueType any_cast(any&& __any) { - using _Up = remove_cv_t>; + using _Up = __remove_cvref_t<_ValueType>; static_assert(any::__is_valid_cast<_ValueType>(), "Template argument must be a reference or CopyConstructible type"); static_assert(is_constructible_v<_ValueType, _Up>, diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 1d0074129b1..16f69220abb 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1499,8 +1499,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Returns the std::tuple equivalent of a tuple-like type. template struct __make_tuple - : public __do_make_tuple::type>::type> + : public __do_make_tuple<__remove_cvref_t<_Tuple>> { }; // Combines several std::tuple's into a single one. diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 711d6c50dd1..7c0ba727511 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2092,6 +2092,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __declval<_Tp>(0); } + // __remove_cvref_t (std::remove_cvref_t for C++11). + template + using __remove_cvref_t + = typename remove_cv::type>::type; + /// result_of template class result_of; @@ -2193,8 +2198,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __result_of_memobj<_Res _Class::*, _Arg> { - typedef typename remove_cv::type>::type _Argval; + typedef __remove_cvref_t<_Arg> _Argval; typedef _Res _Class::* _MemPtr; typedef typename conditional<__or_, is_base_of<_Class, _Argval>>::value, @@ -2209,8 +2213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __result_of_memfun<_Res _Class::*, _Arg, _Args...> { - typedef typename remove_cv::type>::type _Argval; + typedef __remove_cvref_t<_Arg> _Argval; typedef _Res _Class::* _MemPtr; typedef typename conditional<__or_, is_base_of<_Class, _Argval>>::value, @@ -2399,8 +2402,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Internal type trait that allows us to sfinae-protect tuple_cat. template struct __is_tuple_like - : public __is_tuple_like_impl::type>::type>::type + : public __is_tuple_like_impl<__remove_cvref_t<_Tp>>::type { }; template @@ -2942,6 +2944,17 @@ template big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ }; + + /// Remove references and cv-qualifiers. + template + struct remove_cvref + { + using type = __remove_cvref_t<_Tp>; + }; + + template + using remove_cvref_t = __remove_cvref_t<_Tp>; + #endif // C++2a _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 48bec528406..f64c037a514 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -289,7 +289,7 @@ namespace __variant size_t __erased_hash(void* __t) { - return std::hash>>{}( + return std::hash<__remove_cvref_t<_Tp>>{}( __variant::__ref_cast<_Tp>(__t)); }