Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::call_traits - Why is gcc giving false for this?

Tags:

c++

gcc

c++11

boost

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?

like image 494
Jesse Good Avatar asked Jun 05 '12 21:06

Jesse Good


1 Answers

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.")

like image 169
James McNellis Avatar answered Sep 30 '22 06:09

James McNellis