Why a
is true
, and b
is false
? Or in other words why T
in foo1
is int const
but return type of foo2
is just int
?
template<typename T>
constexpr bool foo1(T &) {
return std::is_const<T>::value;
}
template<typename T>
T foo2(T &);
int main() {
int const x = 0;
constexpr bool a = foo1(x);
constexpr bool b = std::is_const<decltype(foo2(x))>::value;
}
The specialization called, const int foo2<const int>(const int&);
, has a return type of const int
, so foo2(x)
would have been a prvalue of type const int
. However, There are no const
(or volatile
) prvalues of non-array, non-class type (in your case, int
). The constness is adjusted away "prior to any further analysis", and it becomes simply a prvalue of type int
, which decltype
reports.
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