Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-03-07 10:03:00


Christoph Borgolte wrote:

[...]

> typedef boost::function<bool(const double& ,const double& )>
> CMP_FNC_DBL_DBL;
> typedef boost::function<bool(const double& )> CMP_FNC_DBL;
> typedef std::map<std::string, CMP_FNC_DBL_DBL> 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("=="));

This gives you a fdd2 that returns fm["=="]. It works because fm["=="] is
convertible to bool, but doesn't really make much sense.

> //that is what I really need: a CMP_FNC_DBL_DBL bound to a constant
> value

CMP_FNC_DBL fdd3 = bind( fdd, _1, 4.0 ); // ?


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