3 ms·
Because decltype(*&value) is int &. The real question to ask is why decltype(value) is int.
by pwdisswordfishc 3y ago
Because decltype(*&value) is int &.
The real question to ask is why decltype(value) is int.
- loeg 3y agoThat doesn't really answer the question. It's not obvious why decltype(*&value) is int& either.
- edflsafoiewq 3y agoNormally decltype(E) returns the type of the expression E. The type of the expressions *&value and value are both int& for instance. However they also wanted a way to query the type an identifier was declared with, eg int x would be int. For some reason they chose to expose this by overriding decltype(E) when E is a plain identifier. decltype((value)) avoids this special case and returns the type of the expression (value), which is obviously the same as the expression value.