I'm using a map of comparing functions, created with Boost.Lambda and
Boost.Function.
These are of type boost::function f = ( _1 <= _2 )
Now I need one of these functions bound to a specific value to send this
function object as a callback function.
Things are compiling fine, but the result is wrong.
I've boiled it down to a minimal example:
Any hints?
TIA
Chris
--------8<--------------8<------------
#include <iostream>
#include <map>
#include
#include
#include
#include
typedef boost::function
CMP_FNC_DBL_DBL;
typedef boost::function CMP_FNC_DBL;
typedef std::map FUNCTION_MAP;
int main()
{
FUNCTION_MAP fm;
fm["=="] = (boost::lambda::_1 == boost::lambda::_2);
fm["!="] = (boost::lambda::_1 != boost::lambda::_2);
//...
CMP_FNC_DBL_DBL fdd = fm["=="];
std::cout << fdd(11., 10.) << std::endl; //works
//Getting a function object via bind
CMP_FNC_DBL_DBL fdd2 = boost::bind(&FUNCTION_MAP::operator[] , fm,
std::string("=="));
std::cout << fdd2(11., 10.) << std::endl; //works not
//that is what I really need: a CMP_FNC_DBL_DBL bound to a constant
value
CMP_FNC_DBL f = boost::bind(boost::bind(&FUNCTION_MAP::operator[] ,
fm, std::string("==")), 4.); //doesnt compile
std::cout << f(3) << std::endl; //works not
}
--------8<--------------8<------------
result:
0
1
1