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 r11-8613] libstdc++: Non-triv-copyable extra args aren't simple [PR100940]
Date: Fri, 18 Jun 2021 03:05:58 +0000 (GMT)	[thread overview]
Message-ID: <20210618030558.4619C3835800@sourceware.org> (raw)

https://gcc.gnu.org/g:f0d8d001d94166242be4387ca72fe0fc483860f1

commit r11-8613-gf0d8d001d94166242be4387ca72fe0fc483860f1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Jun 17 09:46:07 2021 -0400

    libstdc++: Non-triv-copyable extra args aren't simple [PR100940]
    
    This force-enables perfect forwarding call wrapper semantics whenever
    the extra arguments of a partially applied range adaptor aren't all
    trivially copyable, so as to avoid incurring unnecessary copies of
    potentially expensive-to-copy objects (such as std::function objects)
    when invoking the adaptor.
    
            PR libstdc++/100940
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (__adaptor::_Partial): For the "simple"
            forwarding partial specializations, also require that
            the extra arguments are trivially copyable.
            * testsuite/std/ranges/adaptors/100577.cc (test04): New test.
    
    (cherry picked from commit 2b87f3318cf6334a3a42dcf27f2fdec0fce04665)

Diff:
---
 libstdc++-v3/include/std/ranges                      |  8 +++++---
 libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 4921afc37df..9d1c4e1356a 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -892,11 +892,12 @@ namespace views::__adaptor
     };
 
   // Partial specialization of the primary template for the case where the extra
-  // arguments of the adaptor can always be safely forwarded by const reference.
-  // This lets us get away with a single operator() overload, which makes
-  // overload resolution failure diagnostics more concise.
+  // arguments of the adaptor can always be safely and efficiently forwarded by
+  // const reference.  This lets us get away with a single operator() overload,
+  // which makes overload resolution failure diagnostics more concise.
   template<typename _Adaptor, typename... _Args>
     requires __adaptor_has_simple_extra_args<_Adaptor, _Args...>
+      && (is_trivially_copyable_v<_Args> && ...)
     struct _Partial<_Adaptor, _Args...> : _RangeAdaptorClosure
     {
       tuple<_Args...> _M_args;
@@ -926,6 +927,7 @@ namespace views::__adaptor
   // where _Adaptor accepts a single extra argument.
   template<typename _Adaptor, typename _Arg>
     requires __adaptor_has_simple_extra_args<_Adaptor, _Arg>
+      && is_trivially_copyable_v<_Arg>
     struct _Partial<_Adaptor, _Arg> : _RangeAdaptorClosure
     {
       _Arg _M_arg;
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc
index 8ef084621f9..06be4980ddb 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/100577.cc
@@ -21,6 +21,7 @@
 // PR libstdc++/100577
 
 #include <ranges>
+#include <functional>
 
 namespace ranges = std::ranges;
 namespace views = std::ranges::views;
@@ -113,4 +114,17 @@ test03()
   x | std::views::drop(S{});
 }
 
+void
+test04()
+{
+  // Non-trivially-copyable extra arguments make a closure not simple.
+  using F = std::function<bool(bool)>;
+  static_assert(!std::is_trivially_copyable_v<F>);
+  using views::__adaptor::__closure_has_simple_call_op;
+  static_assert(!__closure_has_simple_call_op<decltype(views::take_while(std::declval<F>()))>);
+  static_assert(!__closure_has_simple_call_op<decltype(views::drop_while(std::declval<F>()))>);
+  static_assert(!__closure_has_simple_call_op<decltype(views::filter(std::declval<F>()))>);
+  static_assert(!__closure_has_simple_call_op<decltype(views::transform(std::declval<F>()))>);
+}
+
 // { dg-prune-output "in requirements" }


                 reply	other threads:[~2021-06-18  3:05 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=20210618030558.4619C3835800@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).