BOOST_TYPEOF returns int instead of const int

Could you explain why this prints 1? Should not be BOOST_TYPEOFreturned const int. How can I check if a function returns constwithout using C ++ 11 functions?

#include <iostream>

#include <boost/typeof/typeof.hpp>
#include <boost/type_traits/is_same.hpp>

const int f_const_int() {return 1;}

int main()
{
    typedef BOOST_TYPEOF(f_const_int()) type;
    std::cout << (boost::is_same<type, int>::value) << std::endl;
}
+4
source share
1 answer

If the prvalue expression is of type cv int, this cv qualifier is ignored. [Expression] / 6:

If the original prvalue value is of type "cv T", where Tis cv-unqualified non-class, non-array type, type of expression before Tuntil the next analysis.

, , const.
:

#include <boost/type_traits/function_traits.hpp>

// […]
typedef boost::function_traits<BOOST_TYPEOF(f_const_int)>::result_type type;

.

+4

All Articles