Bimap compare function
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 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); } }; Regards, Nate
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.
participants (3)
-
Edward Diener
-
Nathan Ridge
-
Tyler Conant