
Originally Posted by
gulHK
and is it possible to write more than one comparison method with different comparison criteria?
A struct can basically do anything you want it to do. All you would need is to pass which criteria you want to use when you construct it.
Code:
struct MyPred
{
std::string x;
std::string y;
int sorting_criteria;
MyPred(const std::string& x, const std::string& y,
int crit = 0): x(x), y(y), sorting_criteria(crit) {}
bool operator()(const MyPred& p1, MyPred& p2) const
{
switch( sorting_criteria )
{
case 0:
return SortThisWay(p1, p2);
case1:
return SortThatWay( p1, p2);
case 2:
return SortAThirdWay( p1, p2);
}
return false;
}
//...
};
That is just a rough outline.
Regards,
Paul McKenzie