I have a question about decltype. For the following code:
#include <iostream>
#include <type_traits>
int main()
{
int a[3];
std::cout << std::is_same_v<decltype((a)), int(&)[3]> << std::endl;
std::cout << std::is_same_v<decltype(a + 0), int*> << std::endl;
}
All of the outputs are 1. But as cppreference said:
If the argument is any other expression of type
T, and if the value category ofexpressionis lvalue (or pvalue), then decltype yieldsT&(orT);
I don't understand why decltype((a)) is int(&)[3], since
ais an array variable, which is not an lvalue(a)is an expression, so I thinkdecltype((a))should return its type, which should be decayed asint*, as the second output shows.
So basically, I don't understand the difference between (a) and a + 0 when using decltype.