Boost logo

Boost :

Subject: Re: [boost] [type_traits][function_types] Discard param const qualification, bug or feature?
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-09-25 02:57:34


2013/9/25 Mostafa <mostafa_working_away_at_[hidden]>

> Both the type_traits and function_types library discard parameter
> const-qualifiers when decomposing function types. Is this a bug or a
> feature? If a feature, then it's surprising enough behaviour that I think
> it warrants some documentation in both libraries. For the record, I'm using
> gcc 4.7.3 on Cygwin 1.7.22 in Windows 7, and here's a reproducible example
> of what I'm talking about:
>
> #include <boost/type_traits.hpp>
> #include <boost/function_types/**parameter_types.hpp>
> #include <boost/mpl/at.hpp>
> #include <boost/mpl/int.hpp>
> #include <boost/mpl/assert.hpp>
>
> using namespace boost;
>
> typedef void (foo)(int const);
>
> int main()
> {
>
> typedef function_traits<foo>::arg1_**type traits_deduced_type;
> BOOST_MPL_ASSERT(( is_same<traits_deduced_type, int> ));
> //Errors:
> //BOOST_MPL_ASSERT(( is_same<traits_deduced_type, int const> ));
>
> typedef boost::function_types::**parameter_types<foo> ftypes_params;
> typedef boost::mpl::at<ftypes_params, boost::mpl::int_<0> >::type
> ftypes_deduced_type;
> BOOST_MPL_ASSERT(( is_same<ftypes_deduced_type, int> ));
> //Errors:
> //BOOST_MPL_ASSERT(( is_same<ftypes_deduced_type, int const> ));
>
> return 0;
> }
>
> Mostafa
>

The two function declarations:
void f(int);
void f(int const);
declare the same function, not an overload. Const added to an argument type
passed by value doesn't change the function signature. It is because the
parameter will be copied anyway, and the const refers to how the argument
will be treated inside the function's implementation.

So in your example, I think the compiler correctly discards the 'const'.

Regards,
Kris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk