C++ Logo

std-proposals

Advanced search

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

From: Bo Persson <bo_at_[hidden]>
Date: Tue, 11 Oct 2022 15:53:19 +0200
On 2022-10-11 at 10:52, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Sun, Oct 9, 2022 at 1:30 PM Arthur O'Dwyer via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> void f(int&&) { puts("int"); }
>> void f(double&&) { puts("double"); }
>>
>> int main() {
>> int i = 1;
>> double d = 2;
>> f(i); // prints "double"
>> f(d); // prints "int"
>> }
>
>
> Please give me a web link, or a short explanation, of why this code
> behaves the way it does.

This of course is silly code that has no use, except on a pub-quiz.

The "fun" part being that int&& doesn't match the int i, because i isn't
an rvalue.

Received on 2022-10-11 13:53:27