C++ Logo


Advanced search

Re: Do we need a way to take *this by value, for coroutines?

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sun, 7 Nov 2021 19:18:59 +0100
Hi ,

On 07/11/2021 19:04, Phil Endecott via Std-Proposals wrote:
> We have ref-qualifiers that allow us to indicate whether a method
> takes *this as an rvalue or lvalue reference, but this mechanism
> doesn't allow it to be taken by value.
> Some similar problems be fixed by taking a copy of *this at the start
> of the method, and there are similar approaches with shared_ptrs
> and enable_shared_from_this, but in a generator coroutine (initial
> suspend = suspend always) there is nowhere to do that.
> Comments anyone?

This should be solved by the "Deducing this" proposal (P0847), which I
believe has just been voted into C++23. Under the syntax introduced by
that paper, you can finally pass `*this` by value to non-static member

Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2021-11-07 12:19:07