D
David Rasmussen
I want to use sort() and supply my own comparison function, like
bool lessThan(const S& a, const S& b)
{
return value(a) < value(b);
}
and then sort by:
sort(a.begin(), a.end(), lessThan);
All trivial stuff, but I have several different metrics or value()
functions if you will. I could copy and paste 100 times so I get 100
functions like:
bool lessThan42(const S& a, const S& b)
{
return value42(a) < value42(b);
}
but isn't there an easier way? Can't I make lessThan a template function
that takes the metric (value() function) as a template argument or some
other smart thing that will save me from all that copying and pasting?
/David
bool lessThan(const S& a, const S& b)
{
return value(a) < value(b);
}
and then sort by:
sort(a.begin(), a.end(), lessThan);
All trivial stuff, but I have several different metrics or value()
functions if you will. I could copy and paste 100 times so I get 100
functions like:
bool lessThan42(const S& a, const S& b)
{
return value42(a) < value42(b);
}
but isn't there an easier way? Can't I make lessThan a template function
that takes the metric (value() function) as a template argument or some
other smart thing that will save me from all that copying and pasting?
/David