C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Return Value Optimisation whenever you need it (guaranteed elision)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 12 Aug 2023 11:58:26 +0100
I reply in series to Thiago and Jason below.


On Sat, Aug 12, 2023 at 3:13 AM Jason McKesson wrote:
>
> p = new(p) mutex(Func(5, 6.3, 8.4f));


That's really cool, I didn't know we could do that. I tried it just
now on Godbolt with an atomic<int>:

    https://godbolt.org/z/znPo9MeET


> There's no equivalent for `optional`, but that's nonsensical.


A window could optionally contain a timer, something like:
    class Window { optional<Timer> timer; };
And then there could be a threadsafe function that allocates timers
from a pool of 8, and blocks until one becomes available.

Not only should we be able to put a unmovable-and-uncopiable return
value inside an 'optional', but we should be able to put it inside a
'variant or an 'any' also.


On Sat, Aug 12, 2023 at 12:13 AM Thiago Macieira wrote:
>
> Attributes are not allowed to modify the syntactic correctness of the program.
> So if the code doesn't compile today without that attribute, the presence of
> the attribute can't make it compile.


I bet ChatGPT can figure this one out. Here's what I typed in:

"Hi ChatGPT, nice to meet you. I'm a computer programmer who programs
primarily in C++ and I want you to help me with something. Normally in
C++, I would define a variable called 'monkey' of type 'int' as
follows:
    int monkey;
I am making a proposal to the C++ programming language whereby it
would be possible to mark a variable with the marker 'nrvo'. I haven't
decided on the syntax yet though. I suggested that the syntax should
be:
    [[nrvo]] int monkey;
but my friend Thiago didn't like that syntax. Could you please suggest
16 different syntaxes? Just to get your creative juices flowing, I
will give you three more example syntaxes:
    <<<nrvo>>> int monkey;
    int monkey -> nrvo;
    int [nrvo]monkey;
Please be very creative and give me 16 different suggestions."

And here is the reply that I got back from ChatGPT:

"Of course, I'd be happy to help! Here are 16 different syntax
suggestions for marking a variable with the "nrvo" optimization hint:

int {monkey} nrvo;
int monkey(nrvo);
int monkey[[nrvo]];
int monkey : nrvo;
int (monkey) nrvo;
int monkey_at_nrvo;
int monkey <nrvo>;
int nrvo monkey;
int monkey ~nrvo~;
int monkey #nrvo;
int monkey %nrvo;
int monkey $nrvo;
int monkey /nrvo/;
int monkey %nrvo%;
~nrvo~ int monkey;
nrvo -> int monkey;

Feel free to mix and match these suggestions or modify them to fit
your proposal. The goal is to find a syntax that's both intuitive and
consistent with existing C++ conventions."


On Sat, Aug 12, 2023 at 12:13 AM Thiago Macieira wrote:
> You didn't even attempt at the main goal.

All is not lost, I got to play around writing assembler for SuperH
which as a stack that grows upwards believe it or not!

Received on 2023-08-12 10:58:36