Boost logo

Boost Users :

Subject: Re: [Boost-users] [Function] "constness" lost on Function Signature
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-02-04 11:56:29


AMDG

On 2/4/2011 1:53 AM, nicolas david wrote:
> I am using boost::function and have some issues on using it with visual
> studio 2005.
> If I declare a boost::function with some "const" argument this "constness"
> seems to be lost on boost function siganture. Then, future assigment to this
> function whith correct "const" argument lead to wrong matching. See code
> snipset below.
> This work fine under gcc 4.4 and visual 2010.
>
> ----------------------------------------------------------------------------------
> <snip>
> class container_test
> {
> public:
> typedef boost::function<bool(const int,float,float)> FunctionType;
> bool static defaultFunctor(const int, float, float) { return true; }
> //void apply_functor( const FunctionType IsInside = defaultFunctor){}
> };
> <snip>
> ----------------------------------------------------------------------------------
>
> error send by visual 2005 compiler with "const". If change "const int" to
> "int" it works.
> ( sorry for the "french")
>

This is a compiler bug. Whether the argument is declared
const shouldn't affect anything outside of the function
body.

bool static defaultFunctor(const int, float, float);

is exactly equivalent to

bool static defaultFunctor(int, float, float);

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net