C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify that argument to function cannot be an rvalue

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 11 Oct 2022 19:15:43 +0300
On Tue, 11 Oct 2022 at 19:09, Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Tuesday, 11 October 2022 04:30:52 PDT Ville Voutilainen via Std-Proposals
> wrote:
> > void f(int&&) { puts("int"); }
> > void f(double&&) { puts("double"); }
> >
> > so
> >
> > int i = 1;
> > f(i);
> >
> > prints "double", because it can't call void f(int&&). Instead, it'll
> > convert the int to double,
> > and call void f(double&&).
>
> But why can't it convert int to int and then call the int&& overload?

Presumably because that would be even weirder if you have just the
int&& overload,
and overloads need to make sense in isolation, not just as members of
an overload set.
A reference parameter still means "don't create an object unless you have to".

Received on 2022-10-11 16:15:55