C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Lorand Szollosi <szollosi.lorand_at_[hidden]>
Date: Mon, 27 May 2024 10:55:47 +0200
Hi,

The proposed std::factory<T>(params…, setup) can be written as T{args…} @ setup() as per the ideas I’ve shown above. Indeed, factory as a function name is a nice notation for it. If we were to extend it so that setup could return a value (that becomes an asdv in the caller scope), then we could have a solution for the ‘returning a char[]’ problem’ and string conversions - but then we have the issue of caller not being aware of the return type of setup. It still doesn’t allow access of this auxiliary returned object (‘annotation’ in my explanation) from the caller, that’d still need a notation. Also, member variable descriptors are not included in that case.

Otoh, based on a @ b, @@, @a primitives [1], std::factory proposal is simply { return T{params…} @ setup(); } and Return Slot proposal is { return @( T{args..} @ [&retval=@@] { /* function body using retval */ }(); } . Anton’s NRVO paper is a bit broader as it changes a currently existing schematic to a new, enforced scemantics.

Thanks,
-lorro
[1] I do not stick to this notation; these are simply 3 primitives for the 7 use cases (prvalue annotation/setup, setup referring to the value being set up, accessing setup’s return value in case of function call, prvalue, member variable, static function-local variable, global variable).

> On 26 May 2024, at 23:24, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Sun, May 26, 2024 at 2:02 AM Lorand Szollosi wrote:
>>
>> The real-world problems are:
>> 1. how to return a char const* to a callee-created char const[fixed_N]
>> that then the caller deallocates (e.g. mocks, char-to-wchar API
>> strings, etc.)
>> 2. how to have a make function for a non-movable class that can fail,
>> without throwing exceptions
>> 3. an alternative with way less noise for in-class description (e.g. field
>> names in serialization, optionality, etc.)
>> 4. how to do a post-constructor setup on a non-movable class without
>> heap allocation
>
>
> Sebastian had a good idea to have a new standard library function
> called 'std::factory', and I've written a paper about it just now:
>
> std::factory : http://www.virjacode.com/papers/factory.htm
>
> So that means we now have 3 papers to choose from in order to achieve
> NRVO. Here are the other two:
>
> Return Slot : http://www.virjacode.com/papers/returnslot.htm
>
> Anton's NRVO paper :
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2025r2
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-05-27 08:56:02