Example:
#include <iostream>
#include <boost/call_traits.hpp>
#include <type_traits>
boost::call_traits<int>::param_type f()
{
return 1;
}
int main()
{
std::cout << std::boolalpha;
std::cout <<
std::is_const<boost::call_traits<int>::param_type>::value
<< std::endl; // true
std::cout << std::is_const<decltype(f())>::value << std::endl; // false
}
Question:
Unless, I am doing something wrong, I think I should be getting true
for both, but gcc 4.7.0 outputs false
for the latter. Is there something I am missing?
A non-class type rvalue is never const-qualified. Only class-type rvalues may be const-qualified.
So, even though the function f
is declared as returning a const int
, and even though the type of the function f
is const int()
, the call expression f()
is an rvalue of type (non-const) int
.
(In the new C++11 expression category taxonomy, the call expression f()
is a prvalue of type int
. The same rule applies: C++11 §3.10/4 states that "non-class prvalues always have cv-unqualified types.")
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