public inbox for
 help / color / mirror / Atom feed
From: Patrick Palka <>
Cc:, Patrick Palka <>
Subject: [PATCH 1/3] libstdc++: Separate construct/convertibility tests for std::tuple
Date: Mon, 22 Aug 2022 21:34:58 -0400	[thread overview]
Message-ID: <> (raw)

P2321R2 adds new conditionally explicit constructors to std::tuple which
we'll concisely implement in a subsequent patch using explicit(bool), like
in our C++20 std::pair implementation.  But before we can do that, this
patch first adds members to _TupleConstraints that test for constructibility
and convertibility separately; we'll use the first in the new constructors'
constraints, and the second in their explicit specifier.

In passing, this patch also redefines the existing predicates
__is_ex/implicitly_constructible in terms of these new members.  This
seems to reduce compile time and memory usage by about 10% for large
tuples when using the relevant constructors constrained by
_Explicit/_ImplicitCtor (since we no longer have to redundantly expand
and process is_constructible<_Types, _UTypes>... twice for each pair of
such constructors).  In order to retain maximal short circuiting, do
this only when constexpr if is available.

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?


	* include/std/tuple (_TupleConstraints::__convertible): Define
	for C++17.
	(_TupleConstraints::__constructible): Likewise.
	(_TupleConstraints::__is_explicitly_constructible): For C++17
	define this in terms of __convertible and __constructible
	using constexpr if.
	(_TupleConstraints::__is_implicitly_constructible): Likewise.
 libstdc++-v3/include/std/tuple | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 6d0060a191c..d0c168fd7e2 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
   template<bool, typename... _Types>
     struct _TupleConstraints
+#if __cplusplus >= 201703L
+      template<typename... _UTypes>
+	static constexpr bool __constructible
+	  = __and_v<is_constructible<_Types, _UTypes>...>;
+      template<typename... _UTypes>
+	static constexpr bool __convertible
+	  = __and_v<is_convertible<_UTypes, _Types>...>;
       // Constraint for a non-explicit constructor.
       // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
       // and every Ui is implicitly convertible to Ti.
       template<typename... _UTypes>
 	static constexpr bool __is_implicitly_constructible()
+#if __cplusplus >= 201703L
+	  if constexpr (__constructible<_UTypes...>)
+	    return __convertible<_UTypes...>;
+	  return false;
 	  return __and_<is_constructible<_Types, _UTypes>...,
 			is_convertible<_UTypes, _Types>...
       // Constraint for a non-explicit constructor.
       template<typename... _UTypes>
 	static constexpr bool __is_explicitly_constructible()
+#if __cplusplus >= 201703L
+	  if constexpr (__constructible<_UTypes...>)
+	    return !__convertible<_UTypes...>;
+	  return false;
 	  return __and_<is_constructible<_Types, _UTypes>...,
 			__not_<__and_<is_convertible<_UTypes, _Types>...>>
       static constexpr bool __is_implicitly_default_constructible()

             reply	other threads:[~2022-08-23  1:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-23  1:34 Patrick Palka [this message]
2022-08-23  1:34 ` [PATCH 2/3] libstdc++: Implement std::pair/tuple/misc enhancements from P2321R2 Patrick Palka
2022-08-23 12:03   ` Jonathan Wakely
2022-08-23 15:14     ` Patrick Palka
2022-08-23  1:35 ` [PATCH 3/3] libstdc++: Implement ranges::zip_view " Patrick Palka
2022-08-24 12:15   ` Jonathan Wakely
2022-08-26 20:05   ` Jonathan Wakely
2022-08-31 10:12     ` Jonathan Wakely
2022-08-23  9:15 ` [PATCH 1/3] libstdc++: Separate construct/convertibility tests for std::tuple Jonathan Wakely
2022-08-23 13:44   ` Patrick Palka
2022-08-23 14:53     ` Jonathan Wakely

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:

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

  git send-email \ \ \ \ \

* 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).