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: [PATCH] Simplify common case of use_future_t that uses std::allocator
Date: Thu, 24 Oct 2019 14:52:00 -0000	[thread overview]
Message-ID: <20191024143947.GA4312@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

There is no need to store and pass around the allocator object when it's
an instance of std::allocator. Define a partial specialization of
std::use_future_t and the corresponding completion token so that no
allocator is stored. Overload the completion handler constructor to not
expect an allocator to be stored.

	* include/experimental/executor (__use_future_ct, use_future_t):
	Define partial specializations for std::allocator.
	(__use_future_ch): Overload constructor for completion tokens using
	std::allocator.

Tested x86_64-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3342 bytes --]

commit ff1859de72d39f46118df4f568ee90d78c6be937
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Oct 24 15:34:17 2019 +0100

    Simplify common case of use_future_t that uses std::allocator
    
    There is no need to store and pass around the allocator object when it's
    an instance of std::allocator. Define a partial specialization of
    std::use_future_t and the corresponding completion token so that no
    allocator is stored. Overload the completion handler constructor to not
    expect an allocator to be stored.
    
            * include/experimental/executor (__use_future_ct, use_future_t):
            Define partial specializations for std::allocator.
            (__use_future_ch): Overload constructor for completion tokens using
            std::allocator.

diff --git a/libstdc++-v3/include/experimental/executor b/libstdc++-v3/include/experimental/executor
index ef141e92cd3..ed18730951c 100644
--- a/libstdc++-v3/include/experimental/executor
+++ b/libstdc++-v3/include/experimental/executor
@@ -1501,12 +1501,18 @@ inline namespace v1
       std::tuple<_Func, _Alloc> _M_t;
     };
 
+  template<typename _Func, typename _Tp>
+    struct __use_future_ct<_Func, std::allocator<_Tp>>
+    {
+      _Func _M_f;
+    };
+
   template<typename _ProtoAllocator = allocator<void>>
     class use_future_t
     {
     public:
       // use_future_t types:
-      typedef _ProtoAllocator allocator_type;
+      using allocator_type = _ProtoAllocator;
 
       // use_future_t members:
       constexpr use_future_t() noexcept : _M_alloc() { }
@@ -1514,7 +1520,7 @@ inline namespace v1
       explicit
       use_future_t(const _ProtoAllocator& __a) noexcept : _M_alloc(__a) { }
 
-      template<class _OtherAllocator>
+      template<typename _OtherAllocator>
 	use_future_t<_OtherAllocator>
 	rebind(const _OtherAllocator& __a) const noexcept
 	{ return use_future_t<_OtherAllocator>(__a); }
@@ -1533,6 +1539,35 @@ inline namespace v1
       _ProtoAllocator _M_alloc;
     };
 
+  template<typename _Tp>
+    class use_future_t<std::allocator<_Tp>>
+    {
+    public:
+      // use_future_t types:
+      using allocator_type = std::allocator<_Tp>;
+
+      // use_future_t members:
+      constexpr use_future_t() noexcept = default;
+
+      explicit
+      use_future_t(const allocator_type& __a) noexcept { }
+
+      template<class _Up>
+	use_future_t<std::allocator<_Up>>
+	rebind(const std::allocator<_Up>& __a) const noexcept
+	{ return use_future_t<std::allocator<_Up>>(__a); }
+
+      allocator_type get_allocator() const noexcept { return {}; }
+
+      template<typename _Func>
+	auto
+	operator()(_Func&& __f) const
+	{
+	  using _Token = __use_future_ct<decay_t<_Func>, allocator_type>;
+	  return _Token{std::forward<_Func>(__f)};
+	}
+    };
+
   constexpr use_future_t<> use_future = use_future_t<>();
 
   template<typename _Func, typename _Alloc, typename _Res, typename... _Args>
@@ -1552,6 +1587,12 @@ inline namespace v1
 	  _M_promise{ std::get<1>(__token._M_t) }
 	{ }
 
+      template<typename _Tp>
+	explicit
+	__use_future_ch(__use_future_ct<_Func, std::allocator<_Tp>>&& __token)
+	: _M_f{ std::move(__token._M_f) }
+	{ }
+
       void
       operator()(_Args&&... __args)
       {

                 reply	other threads:[~2019-10-24 14:52 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=20191024143947.GA4312@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).