C++ Logo

std-proposals

Advanced search

Re: [std-proposals] this return type

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Fri, 07 Apr 2023 23:08:31 +0100
On Fri, 2023-04-07 at 23:28 +0200, Jens Maurer wrote:
>
>
> On 07/04/2023 22.04, Lénárd Szolnoki via Std-Proposals wrote:
> > An alternative approach is that Base has a private `virtual void
> > do_fun1()` member function and a public inline `Base& fun1() {
> > do_fun1(); return *this; }` member function. This should achieve
> > the
> > same performance as the proposed this return type.
>
> I can't get any compiler convinced to do the right thing for this
> setup:
>
> https://www.godbolt.org/z/a8MTqqzvv

Interesting. This feels like a missed optimisation. At least I don't
think the dynamic type of `*this` can change after an invocation to
`do_fun1()`.

>
> Jens

Cheers,
Lénárd

Received on 2023-04-08 14:09:16