What does rvalue address address mean?

Considering

void foo( int&& x ) { std::cout << &x; } 

It works, but what is this address? Is the temporary int created by calling foo, and is that what the address represents? If this is true, and if I write int y = 5; foo(static_cast<int&&>(y)); int y = 5; foo(static_cast<int&&>(y)); Does this mean another temporary creation or is the compiler reasonably referencing y?

+7
c ++ c ++ 11 c ++ 14
source share
1 answer

When you take the address of the rvalue link, it returns a pointer to the object to which the link is bound, for example, with lvalue links. The object can be temporary or not (if, for example, you set the value of lvalue to rvalue, as in the code).

int y = 5; foo(static_cast<int&&>(y)); does not create temporary. This conversion is described in part 5.2.9/3 standard:

The value of a glvalue, a prvalue class, or a prvalue array of type " cv1 T1 " can be distinguished to enter "rvalue reference to cv2 T2 " if " cv2 T2 " refers to " cv1 T1 ".

A temporary creation will be created if, for example, you call foo(1); .

+7
source share

All Articles