From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: Tim Song <t.canens.cpp@gmail.com>,
libstdc++ <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Implement P2328 changes to join_view
Date: Fri, 30 Apr 2021 23:01:14 +0100 [thread overview]
Message-ID: <20210430220114.GE3008@redhat.com> (raw)
In-Reply-To: <21f9ca23-18bb-fafe-4028-bd5fc1f4d3c@idea>
On 30/04/21 17:34 -0400, Patrick Palka via Libstdc++ wrote:
>On Fri, 30 Apr 2021, Tim Song wrote:
>
>> On Fri, Apr 30, 2021 at 12:11 PM Patrick Palka via Libstdc++
>> <libstdc++@gcc.gnu.org> wrote:
>> >
>> > + template<typename _Iter>
>> > + _Tp&
>> > + _M_emplace_deref(const _Iter& __i)
>> > + {
>> > + this->reset();
>> > + return this->emplace(*__i);
>> > + }
>>
>> This incurs a move, avoiding of which is the sole reason for
>> emplace-deref's existence.
>
>Ah thanks, I had missed that... IIUC, if we instead derive from
>optional's internal base class _Optional_base, we can easily get at the
>underlying storage for the object and directly initialize it with '*__i'
>and avoid the move. How does the the following adjustment to the patch
>look?
Looks good to me, thanks.
>-- >8 --
>
>diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
>
>index 971898f5492..f1db4a238ef 100644
>--- a/libstdc++-v3/include/std/ranges
>+++ b/libstdc++-v3/include/std/ranges
>@@ -2254,7 +2254,7 @@ namespace views::__adaptor
>
> template<typename _Tp>
> requires is_object_v<_Tp>
>- struct __non_propagating_cache<_Tp> : private optional<_Tp>
>+ struct __non_propagating_cache<_Tp> : private _Optional_base<_Tp>
> {
> __non_propagating_cache() = default;
>
>@@ -2264,32 +2264,36 @@ namespace views::__adaptor
>
> constexpr
> __non_propagating_cache(__non_propagating_cache&& __other) noexcept
>- { __other.reset(); }
>+ { __other._M_reset(); }
>
> constexpr __non_propagating_cache&
> operator=(const __non_propagating_cache& __other) noexcept
> {
> if (std::__addressof(__other) != this)
>- this->reset();
>+ this->_M_reset();
> return *this;
> }
>
> constexpr __non_propagating_cache&
> operator=(__non_propagating_cache&& __other) noexcept
> {
>- this->reset();
>- __other.reset();
>+ this->_M_reset();
>+ __other._M_reset();
> return *this;
> }
>
>- using optional<_Tp>::operator*;
>+ constexpr _Tp&
>+ operator*() noexcept
>+ { return this->_M_get(); }
>
> template<typename _Iter>
> _Tp&
> _M_emplace_deref(const _Iter& __i)
> {
>- this->reset();
>- return this->emplace(*__i);
>+ this->_M_reset();
>+ ::new ((void *) std::__addressof(this->_M_payload._M_payload)) _Tp(*__i);
>+ this->_M_payload._M_engaged = true;
>+ return this->_M_get();
> }
> };
> }
>
next prev parent reply other threads:[~2021-04-30 22:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-30 14:38 Patrick Palka
2021-04-30 16:59 ` Jonathan Wakely
2021-04-30 17:43 ` Tim Song
2021-04-30 21:34 ` Patrick Palka
2021-04-30 22:01 ` Jonathan Wakely [this message]
2021-04-30 22:51 ` Patrick Palka
2021-04-30 22:02 ` 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:
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=20210430220114.GE3008@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=ppalka@redhat.com \
--cc=t.canens.cpp@gmail.com \
/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).