Consider the following code:
int&& x = 42;
static_assert(std::is_same<decltype( x ), int&&>::value, "&&");
static_assert(std::is_same<decltype((x)), int& >::value, "&" );
So, what is the type of x
? Is it an int&&
or an int&
?
(I asked myself this question after reading this answer.)
The type of x
(of the variable) is int&&
. So decltype(x)
yields int&&
. The type of the expression x
is int
. If the expression is an lvalue, decltype((x))
yields a lvalue reference to the type of the expression. So decltype((x))
yields int&
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With