C++ Logo

std-proposals

Advanced search

Re: [std-proposals] The syntax of forward and move macros

From: Михаил Найденов <mihailnajdenov_at_[hidden]>
Date: Mon, 29 Aug 2022 18:25:30 +0300
On Mon, Aug 29, 2022 at 5:08 PM Marcin Jaczewski <
marcinjaczewski86_at_[hidden]> wrote:

> pon., 29 sie 2022 o 15:54 Михаил Найденов via Std-Proposals
> <std-proposals_at_[hidden]> napisał(a):
> >
> > I personally think, this should be a minimal-syntax, non-overridable,
> unary postscript operator that will work for both forward and move, much
> like cast-to-T&& today
> >
> > template <typename T> Dog(T&& name) : name(name&&) //< forward
> > {}
> >
> > Name(string&& aName) : name(aName&&) //< move
> >
> > {
> >
> > cout << "Rvalue Name constructor." << endl;
> >
> > }
> >
> > If there is ambiguity with binary operator &&, the latter is chosen
> > template<class T>
> > void func(T&& a, int b) {
> > a&&-b //< ok, still operator&&(a,-b)
> >
> > (a&&)-b //< ok, std::forward<T>(a) - b;
> > }
>
>

> Should this be the other way around? `&&a` not `a&&`?
> As far I understand this is available in standard but it is used by
> computed goto labels in GCC.
>

Nah, the idea is not have the association with address-of (double ampersand
before a value looks like address-of-address-of, similar to the
pointer-to-pointer syntax)
where if it is behind, has the association of universal/r-value references
(behind the type, now behind the value, simple)

Lastly, this way one can have usage as:
value&&.member()
value&&()

Which will do forward-and-call, something often needed in generic code.
Because we lack a natural syntax, and the official one is a nightmare, some
people, like Eric Niebler, are forced into using the hacky c-cast

something((T&&)value)

Or alternatively, people invent a FWD macro... which is a macro.

Received on 2022-08-29 15:25:42