#include <iostream>
void foo( int*&& ) { std::cout << "foo( int*&& )\n" ; }
void foo( int&& ) { std::cout << "foo( int&& )\n" ; }
void bar( int* const& ) { std::cout << "foo( int* const& )\n" ; }
void bar( const int& ) { std::cout << "bar( const int& )\n" ; }
void baz( int*& ) { std::cout << "foo( int*& )\n" ; }
void foo( int& ) { std::cout << "foo( int& )\n" ; }
void foobar( int* ) { std::cout << "foobar( int* )\n" ; }
void foobar( int ) { std::cout << "foobar( int )\n" ; }
int main()
{
int a [] = {10,10,10,10,10,11,10,11};
short s = 23 ;
foo(a); // fine a => rvalue of type int*; passed by reference to rvalue
foo(s); // fine s => rvalue of type int; passed by reference to rvalue
bar(a) ; // fine a => rvalue of type int*; passed by reference to const
bar(s) ; // fine s => rvalue of type int; passed by reference to const
// baz(a) ; // *** error, can't pass rvalue as reference to non-const lvalue
//baz(s) ; // *** error, can't pass rvalue as reference to non-const lvalue
foobar(a) ; // fine a => rvalue of type int*; passed by value (pass a copy of the rvalue)
foobar(s) ; // fine s => rvalue of type int; passed by value (pass a copy of the rvalue)
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCBmb28oIGludComJiAgKSB7IHN0ZDo6Y291dCA8PCAiZm9vKCBpbnQqJiYgIClcbiIgOyB9CnZvaWQgZm9vKCBpbnQmJiAgKSB7IHN0ZDo6Y291dCA8PCAiZm9vKCBpbnQmJiAgKVxuIiA7IH0KCnZvaWQgYmFyKCBpbnQqIGNvbnN0JiAgKSB7IHN0ZDo6Y291dCA8PCAiZm9vKCBpbnQqIGNvbnN0JiAgKVxuIiA7IH0Kdm9pZCBiYXIoIGNvbnN0IGludCYgICkgeyBzdGQ6OmNvdXQgPDwgImJhciggY29uc3QgaW50JiAgKVxuIiA7IH0KCnZvaWQgYmF6KCBpbnQqJiAgKSB7IHN0ZDo6Y291dCA8PCAiZm9vKCBpbnQqJiAgKVxuIiA7IH0Kdm9pZCBmb28oIGludCYgICkgeyBzdGQ6OmNvdXQgPDwgImZvbyggaW50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