Boost logo

Boost Users :

Subject: Re: [Boost-users] Bimap compare function
From: Edward Diener (eldiener_at_[hidden])
Date: 2012-05-05 00:48:51


On 5/4/2012 11:38 PM, Nathan Ridge wrote:
>
>> I noticed that the comparator for a bimap can only be a Functor Type.
>> It does not appear that I can pass a function object or a function
>> pointer, as a STL Set would allow. Is this correct or did I miss
>> something. For my application I could really use the ability to pass in
>> comparator which is decided at runtime. Does anyone have any
>> suggestions on a work around?
>
> I'm not familiar with bimap, but is there a reason you can't wrap a
> function pointer (that can change at runtime) in a functor? Something
> like:
>
> typedef int (*function_type)(int);
>
> struct my_functor
> {
> function_type f; // change this at runtime
>
> int operator()(int i)
> {
> return f(i);
> }
> };

Better yet is to delare function_type as:

typedef boost::function<int (int)> function_type;

and then you can set 'f' to any function type object before calling it.


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