public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-2522] libstdc++: Optimize is_void and is_null_pointer
Date: Wed,  7 Sep 2022 14:23:10 +0000 (GMT)	[thread overview]
Message-ID: <20220907142310.787273850849@sourceware.org> (raw)

https://gcc.gnu.org/g:66af6e991bf0daf1c41e46400a8f19e87c358cf2

commit r13-2522-g66af6e991bf0daf1c41e46400a8f19e87c358cf2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Sep 7 10:21:45 2022 -0400

    libstdc++: Optimize is_void and is_null_pointer
    
    Instead of defining these in terms of a helper class template
    and the relatively expensive __remove_cv_t, just declare four
    explicit specializations of the main template, one for each choice
    of cv-quals.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/type_traits (__is_void_helper): Remove.
            (is_void): Make the primary template derive from false_type,
            and define four explicit specializations that derive from
            true_type.
            (__is_null_pointer_helper, is_null_pointer): Likewise.

Diff:
---
 libstdc++-v3/include/std/type_traits | 48 +++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index e4d167939d9..b83e7257a9f 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -289,23 +289,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // __remove_cv_t (std::remove_cv_t for C++11).
   template<typename _Tp>
     using __remove_cv_t = typename remove_cv<_Tp>::type;
+  /// @endcond
 
   // Primary type categories.
 
-  template<typename>
-    struct __is_void_helper
+  /// is_void
+  template<typename _Tp>
+    struct is_void
     : public false_type { };
 
   template<>
-    struct __is_void_helper<void>
+    struct is_void<void>
     : public true_type { };
-  /// @endcond
 
-  /// is_void
-  template<typename _Tp>
-    struct is_void
-    : public __is_void_helper<__remove_cv_t<_Tp>>::type
-    { };
+  template<>
+    struct is_void<const void>
+    : public true_type { };
+
+  template<>
+    struct is_void<volatile void>
+    : public true_type { };
+
+  template<>
+    struct is_void<const volatile void>
+    : public true_type { };
 
   /// @cond undocumented
   template<typename>
@@ -571,19 +578,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #define __cpp_lib_is_null_pointer 201309L
 
-  template<typename>
-    struct __is_null_pointer_helper
+  /// is_null_pointer (LWG 2247).
+  template<typename _Tp>
+    struct is_null_pointer
     : public false_type { };
 
   template<>
-    struct __is_null_pointer_helper<std::nullptr_t>
+    struct is_null_pointer<std::nullptr_t>
     : public true_type { };
 
-  /// is_null_pointer (LWG 2247).
-  template<typename _Tp>
-    struct is_null_pointer
-    : public __is_null_pointer_helper<__remove_cv_t<_Tp>>::type
-    { };
+  template<>
+    struct is_null_pointer<const std::nullptr_t>
+    : public true_type { };
+
+  template<>
+    struct is_null_pointer<volatile std::nullptr_t>
+    : public true_type { };
+
+  template<>
+    struct is_null_pointer<const volatile std::nullptr_t>
+    : public true_type { };
 
   /// __is_nullptr_t (deprecated extension).
   /// @deprecated Non-standard. Use `is_null_pointer` instead.

                 reply	other threads:[~2022-09-07 14:23 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=20220907142310.787273850849@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).