J
jason.cipriani
How can I use my own custom comparison function with
std::list::sort()? The only call to sort() I see does not take a
predicate argument.
Specifically, I have:
list<pair<double,MyType> > ...;
And I want to sort only on the value of the first member in that pair.
My solution right now is to not use a pair; doing something like this
instead:
struct A {
double d;
MyType t;
bool operator < (const A &a) const {
return d < a.d;
}
};
list<A> ...;
But I am wondering how to do it in general.
Thanks,
Jason
std::list::sort()? The only call to sort() I see does not take a
predicate argument.
Specifically, I have:
list<pair<double,MyType> > ...;
And I want to sort only on the value of the first member in that pair.
My solution right now is to not use a pair; doing something like this
instead:
struct A {
double d;
MyType t;
bool operator < (const A &a) const {
return d < a.d;
}
};
list<A> ...;
But I am wondering how to do it in general.
Thanks,
Jason