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++: Optimize constructible/assignable variable templates
Date: Fri,  2 Sep 2022 17:01:40 +0100	[thread overview]
Message-ID: <20220902160140.414197-1-jwakely@redhat.com> (raw)

Tested powerpc64le-linux, pushed to trunk.

-- >8 --

This defines the is_xxx_constructible_v and is_xxx_assignable_v variable
templates by using the built-ins directly. The actual logic for each one
is the same as the corresponding class template, but way using the
variable template doesn't need to instantiate the class template.

This means that the variable templates won't use the static assertions
checking for complete types, cv void or unbounded arrays, but that's OK
because the built-ins check those anyway. We could probably remove the
static assertions from the class templates, and maybe from all type
traits that use a built-in.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_constructible_v)
	(is_default_constructible_v, is_copy_constructible_v)
	(is_move_constructible_v): Define using __is_constructible.
	(is_assignable_v, is_copy_assignable_v, is_move_assignable_v):
	Define using __is_assignable.
	(is_trivially_constructible_v)
	(is_trivially_default_constructible_v)
	(is_trivially_copy_constructible_v)
	(is_trivially_move_constructible_v): Define using
	__is_trivially_constructible.
	(is_trivially_assignable_v, is_trivially_copy_assignable_v)
	(is_trivially_move_assignable_v): Define using
	__is_trivially_assignable.
	(is_nothrow_constructible_v)
	(is_nothrow_default_constructible_v)
	(is_nothrow_copy_constructible_v)
	(is_nothrow_move_constructible_v): Define using
	__is_nothrow_constructible.
	(is_nothrow_assignable_v, is_nothrow_copy_assignable_v)
	(is_nothrow_move_assignable_v): Define using
	__is_nothrow_assignable.
---
 libstdc++-v3/include/std/type_traits | 88 ++++++++++++++++------------
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index be9f2955539..2f5fe80b98a 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3105,71 +3105,81 @@ template <typename _Tp>
   inline constexpr bool is_signed_v = is_signed<_Tp>::value;
 template <typename _Tp>
   inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
+
 template <typename _Tp, typename... _Args>
-  inline constexpr bool is_constructible_v =
-    is_constructible<_Tp, _Args...>::value;
+  inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
 template <typename _Tp>
-  inline constexpr bool is_default_constructible_v =
-    is_default_constructible<_Tp>::value;
+  inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
 template <typename _Tp>
-  inline constexpr bool is_copy_constructible_v =
-    is_copy_constructible<_Tp>::value;
+  inline constexpr bool is_copy_constructible_v
+    = __is_constructible(_Tp, __add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_move_constructible_v =
-    is_move_constructible<_Tp>::value;
+  inline constexpr bool is_move_constructible_v
+    = __is_constructible(_Tp, __add_rval_ref_t<_Tp>);
+
 template <typename _Tp, typename _Up>
-  inline constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value;
+  inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Up);
 template <typename _Tp>
-  inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
+  inline constexpr bool is_copy_assignable_v
+    = __is_assignable(__add_lval_ref_t<_Tp>, __add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
+  inline constexpr bool is_move_assignable_v
+    = __is_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
+
 template <typename _Tp>
   inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
+
 template <typename _Tp, typename... _Args>
-  inline constexpr bool is_trivially_constructible_v =
-    is_trivially_constructible<_Tp, _Args...>::value;
+  inline constexpr bool is_trivially_constructible_v
+    = __is_trivially_constructible(_Tp, _Args...);
 template <typename _Tp>
-  inline constexpr bool is_trivially_default_constructible_v =
-    is_trivially_default_constructible<_Tp>::value;
+  inline constexpr bool is_trivially_default_constructible_v
+    = __is_trivially_constructible(_Tp);
 template <typename _Tp>
-  inline constexpr bool is_trivially_copy_constructible_v =
-    is_trivially_copy_constructible<_Tp>::value;
+  inline constexpr bool is_trivially_copy_constructible_v
+    = __is_trivially_constructible(_Tp, __add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_trivially_move_constructible_v =
-    is_trivially_move_constructible<_Tp>::value;
+  inline constexpr bool is_trivially_move_constructible_v
+    = __is_trivially_constructible(_Tp, __add_rval_ref_t<_Tp>);
+
 template <typename _Tp, typename _Up>
-  inline constexpr bool is_trivially_assignable_v =
-    is_trivially_assignable<_Tp, _Up>::value;
+  inline constexpr bool is_trivially_assignable_v
+    = __is_trivially_assignable(_Tp, _Up);
 template <typename _Tp>
-  inline constexpr bool is_trivially_copy_assignable_v =
-    is_trivially_copy_assignable<_Tp>::value;
+  inline constexpr bool is_trivially_copy_assignable_v
+    = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
+				__add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_trivially_move_assignable_v =
-    is_trivially_move_assignable<_Tp>::value;
+  inline constexpr bool is_trivially_move_assignable_v
+    = __is_trivially_assignable(__add_lval_ref_t<_Tp>,
+				__add_rval_ref_t<_Tp>);
 template <typename _Tp>
   inline constexpr bool is_trivially_destructible_v =
     is_trivially_destructible<_Tp>::value;
 template <typename _Tp, typename... _Args>
-  inline constexpr bool is_nothrow_constructible_v =
-    is_nothrow_constructible<_Tp, _Args...>::value;
+  inline constexpr bool is_nothrow_constructible_v
+    = __is_nothrow_constructible(_Tp, _Args...);
 template <typename _Tp>
-  inline constexpr bool is_nothrow_default_constructible_v =
-    is_nothrow_default_constructible<_Tp>::value;
+  inline constexpr bool is_nothrow_default_constructible_v
+    = __is_nothrow_constructible(_Tp);
 template <typename _Tp>
-  inline constexpr bool is_nothrow_copy_constructible_v =
-    is_nothrow_copy_constructible<_Tp>::value;
+  inline constexpr bool is_nothrow_copy_constructible_v
+    = __is_nothrow_constructible(_Tp, __add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_nothrow_move_constructible_v =
-    is_nothrow_move_constructible<_Tp>::value;
+  inline constexpr bool is_nothrow_move_constructible_v
+    = __is_nothrow_constructible(_Tp, __add_rval_ref_t<_Tp>);
+
 template <typename _Tp, typename _Up>
-  inline constexpr bool is_nothrow_assignable_v =
-    is_nothrow_assignable<_Tp, _Up>::value;
+  inline constexpr bool is_nothrow_assignable_v
+    = __is_nothrow_assignable(_Tp, _Up);
 template <typename _Tp>
-  inline constexpr bool is_nothrow_copy_assignable_v =
-    is_nothrow_copy_assignable<_Tp>::value;
+  inline constexpr bool is_nothrow_copy_assignable_v
+    = __is_nothrow_assignable(__add_lval_ref_t<_Tp>,
+			      __add_lval_ref_t<const _Tp>);
 template <typename _Tp>
-  inline constexpr bool is_nothrow_move_assignable_v =
-    is_nothrow_move_assignable<_Tp>::value;
+  inline constexpr bool is_nothrow_move_assignable_v
+    = __is_nothrow_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>);
+
 template <typename _Tp>
   inline constexpr bool is_nothrow_destructible_v =
     is_nothrow_destructible<_Tp>::value;
-- 
2.37.2


                 reply	other threads:[~2022-09-02 16:01 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=20220902160140.414197-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).