Boost logo

Boost Users :

Subject: [Boost-users] [Function] "constness" lost on Function Signature
From: nicolas david (ericnico.david_at_[hidden])
Date: 2011-02-04 04:53:46


Hi,
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.

----------------------------------------------------------------------------------
#include <iostream>
#include <vector>
#include <boost/function.hpp>

using namespace std;
using namespace boost;

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){}
};

int main() {
    container_test my_container;
    container_test::FunctionType my_f;
    my_f = container_test::defaultFunctor;
    //my_container.apply_functor();
    return 0;
}

----------------------------------------------------------------------------------

error send by visual 2005 compiler with "const". If change "const int" to
"int" it works.
 ( sorry for the "french")

----------------------------------------------------------------------------------
>main.cpp
1>..\main.cpp(22) : error C2679: '=' binaire : aucun opérateur trouvé qui
accepte un opérande de partie droite de type 'bool (__cdecl *)(const
int,float,float)' (ou il n'existe pas de conversion acceptable)
1> C:\Documents and
Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1103):
peut être 'boost::function<Signature> &boost::function<Signature>::operator
=<bool(__cdecl *)(int,float,float)>(Functor)'
1> with
1> [
1> Signature=bool (int,float,float),
1> Functor=bool (__cdecl *)(int,float,float)
1> ]
1> C:\Documents and
Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1088):
ou 'boost::function<Signature> &boost::function<Signature>::operator =(const
boost::function<Signature> &)'
1> with
1> [
1> Signature=bool (int,float,float)
1> ]
1> C:\Documents and
Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1110):
ou 'boost::function<Signature> &boost::function<Signature>::operator
=(boost::function<Signature>::clear_type *)'
1> with
1> [
1> Signature=bool (int,float,float)
1> ]
1> C:\Documents and
Settings\dfc\Bureau\boost_1_44\boost/function/function_template.hpp(1117):
ou 'boost::function<Signature> &boost::function<Signature>::operator =(const
boost::function3<R,T0,T1,T2> &)'
1> with
1> [
1> Signature=bool (int,float,float),
1> R=bool,
1> T0=int,
1> T1=float,
1> T2=float
1> ]
1> lors de la tentative de mise en correspondance de la liste des
arguments '(container_test::FunctionType, bool (__cdecl *)(const
int,float,float))'
----------------------------------------------------------------------------------

Nicolas David



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