public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Remove __is_referenceable helper
Date: Thu,  1 Sep 2022 20:33:59 +0100	[thread overview]
Message-ID: <20220901193359.352625-1-jwakely@redhat.com> (raw)

Tested powerpc64le-linux, pushed to trunk.

-- >8 --

We only use the __is_referenceable helper in three places now:
add_pointer, add_lvalue_reference, and add_rvalue_reference. But lots of
other traits depend on add_[lr]value_reference, and decay depends on
add_pointer, so removing the instantiation of __is_referenceable helps
compile all those other traits slightly faster.

We can just use void_t<T&> to check for a referenceable type in the
add_[lr]value_reference traits.

Then we can specialize add_pointer for reference types, so that we don't
need to use remove_reference, and then use void_t<T*> for all
non-reference types to detect when we can form a pointer to the type.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (__is_referenceable): Remove.
	(__add_lvalue_reference_helper, __add_rvalue_reference_helper):
	Use __void_t instead of __is_referenceable.
	(__add_pointer_helper): Likewise.
	(add_pointer): Add partial specializations for reference types.
---
 libstdc++-v3/include/std/type_traits | 37 ++++++++++++----------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 3041ac3c941..8b11f31741b 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -712,18 +712,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // __void_t (std::void_t for C++11)
   template<typename...> using __void_t = void;
-
-  // Utility to detect referenceable types ([defns.referenceable]).
-
-  template<typename _Tp, typename = void>
-    struct __is_referenceable
-    : public false_type
-    { };
-
-  template<typename _Tp>
-    struct __is_referenceable<_Tp, __void_t<_Tp&>>
-    : public true_type
-    { };
   /// @endcond
 
   // Type properties.
@@ -1024,12 +1012,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
   /// @cond undocumented
-  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+  template<typename _Tp, typename = void>
     struct __add_lvalue_reference_helper
     { using type = _Tp; };
 
   template<typename _Tp>
-    struct __add_lvalue_reference_helper<_Tp, true>
+    struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>>
     { using type = _Tp&; };
 
   template<typename _Tp>
@@ -1046,12 +1034,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
   /// @cond undocumented
-  template<typename _Tp, bool = __is_referenceable<_Tp>::value>
+  template<typename _Tp, typename = void>
     struct __add_rvalue_reference_helper
     { using type = _Tp; };
 
   template<typename _Tp>
-    struct __add_rvalue_reference_helper<_Tp, true>
+    struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>>
     { using type = _Tp&&; };
 
   template<typename _Tp>
@@ -1971,14 +1959,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>>
     { };
 
-  template<typename _Tp, bool = __or_<__is_referenceable<_Tp>,
-				      is_void<_Tp>>::value>
+  template<typename _Tp, typename = void>
     struct __add_pointer_helper
-    { typedef _Tp     type; };
+    { using type = _Tp; };
 
   template<typename _Tp>
-    struct __add_pointer_helper<_Tp, true>
-    { typedef typename remove_reference<_Tp>::type*     type; };
+    struct __add_pointer_helper<_Tp, __void_t<_Tp*>>
+    { using type = _Tp*; };
 
   /// add_pointer
   template<typename _Tp>
@@ -1986,6 +1973,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __add_pointer_helper<_Tp>
     { };
 
+  template<typename _Tp>
+    struct add_pointer<_Tp&>
+    { using type = _Tp*; };
+
+  template<typename _Tp>
+    struct add_pointer<_Tp&&>
+    { using type = _Tp*; };
+
 #if __cplusplus > 201103L
   /// Alias template for remove_pointer
   template<typename _Tp>
-- 
2.37.2


                 reply	other threads:[~2022-09-01 19:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220901193359.352625-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).