(C++) I've got a number of Entry classes, and got BaseProcessor interface which incapsulates Entry processing logic. (see code below)
The Entry doesn't provide operator<(). The BaseProcessor provides a pointer to less(Entry, Entry) function which is specific for particular BaseProcessor implementation.
I can use the function pointer to compare Entry instances in my program. However I need to create std::set (or std::map, or something else that uses less() ) for Entry class. I've tried to use std::binary_function derived class to pass it to std::set, but it looks like I can't pass a function pointer value to a template.
How can I do this? Is it possible with C++03?
Thanks.
struct Entry
{
// ...
private:
bool operator< (const Entry &) const; // Should be defined by BaseProcessor.
};
typedef bool (*LessFunc)(const Entry &, const Entry &);
class BaseProcessor
{
public:
// ...
virtual LessFunc getLessFunc () const = 0;
};
// ...
BaseProcessor *processor = getProcessor();
LessFunc lessfunc = processor->getLessFunc();
Entry e1;
Entry e2;
bool isLess = lessfunc(e1, e2); // OK
typedef std::set<Entry, ???> EntrySetImpl; // how to use lessfunc here?
EntrySetImpl entries;