C++ Logo


Advanced search

Re: [std-proposals] std::elide

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 1 Apr 2024 15:38:22 +0100
On Tue, Mar 12, 2024 at 7:31 PM Jonathan Wakely wrote:
> I would drop all the times you say the changes are small, and the
> count of how many words you want to add to the core language section.

I've made both changes you suggested. Also the constructor for the
class 'std::elide' now has an explicit deduction guide, meaning we
don't need to have a separate "std::elide_t". Latest draft:


> N.B. emplace_invoke is a thing that almost exists in the standard
> already, but not exposed to users directly.
> The non-propagating-cache impl detail has an emplace_deref member:
> https://eel.is/c++draft/range.nonprop.cache#1.6
> And you can get similar effects to emplace_invoke using
> std::optional::transform which constructs an optional from the result
> of an invocable. So implementations kind of need to have the
> functionality of emplace_invoke present in std::optional already.

I'm thinking of extending the paper so that it makes two proposals:
1) Add 'std::elide' to the standard library
2) Add a new method called 'emplace_invoke' to std::optional, variant, any, etc.

You might be thinking, 'Why add both? Why not just choose one?". Well
if we add 'std::elide', then existing code that uses 'emplace' doesn't
need to be altered -- i.e. the same method called 'emplace' can be
used for emplacing copies/moves of pre-existing objects, or it can
invoke a function. There's no need to go editing header files for
classes in libraries such as Boost which have an 'emplace' method.

And so if we have 'std::elide', then why also push for
'emplace_invoke'? The latter wouldn't be needed at all, it would just
be an alternative.

Received on 2024-04-01 14:38:06