C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Lorand Szollosi <szollosi.lorand_at_[hidden]>
Date: Mon, 27 May 2024 21:12:16 +0200
Hi,

On Mon, May 27, 2024 at 11:43 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

> If we were designing a new programming language from scratch, that
> might be a nice idea. But today in 2024 making changes to C++, I think
> it's an extreme change to the core language.
>
> It's always going to be easier to convince the committee to add
> something to the standard library, than to change the core language.
> Plus, core language changes are a lot of work for compiler vendors.
>

By this logic, std::factory<>() were also a core language change, as it's
impossible to implement in terms of currently existing language features.
Simply wrapping it into a library function doesn't change this fact.
Note also, the @-notation I used is *merely a notation*. It was described
as operators, but if you prefer, you could do:

   - return std::factory<T>(params..., setup); instead of return
   T{params...} @ setup(@@);
   - std::factory_return_cast(f_that_returns_via_factory()) instead of @
   f_that returns_via_factory()
   - since setup takes reference of the return value, @@ is not needed.

Then, either this is also not a core language change or the other two are
also (see below).


> Also just now I had another idea with regard to the "Return Slot"
> idea.
>
[...]

> Then we change it so that it calls "std::return_slot" to get the
> address, and we use "construct_at":
>
> void Func(void)
> {
> mutex *const p = std::construct_at<mutex>( std::return_slot() );
>

This brings a whole new set of pandora boxes: functions that don't specify
return type on declaration, thus linker introspection is required, calling
convention changes for the allocation, type system breaks (how does
std::nrvo "know" that the return type of Func2 is std::mutex? What if we
call Func directly? What if there are two uses of std::nrvo in Func, with
different types assumed? What if coder doesn't use std::construct_at<>()
but uses something else?).

(Also, I'd suggest to consider Tiago's notes and change std::mutex to
something else, e.g. std::semaphore.)

Thanks,
-lorro

Received on 2024-05-27 19:12:30