M
matthias_k
Hi,
I need to sort elements of a std::list using a function predicate,
something like:
bool predicate( const& M m1, const& M m2 ) {
return m1.somedata < m2.somedata;
}
I tried to call std::list::sort with such a predicate but that doesn't work:
mylist.sort( predicate ); // error, no matching function call
So since I must not call std::sort on a list, how can I sort it in a way
other than the standard operator< of its element does?
I need to do it with predicates, because I need to sort the list with
different sorting criterions, depending on the situation.
Regards,
Matthias
I need to sort elements of a std::list using a function predicate,
something like:
bool predicate( const& M m1, const& M m2 ) {
return m1.somedata < m2.somedata;
}
I tried to call std::list::sort with such a predicate but that doesn't work:
mylist.sort( predicate ); // error, no matching function call
So since I must not call std::sort on a list, how can I sort it in a way
other than the standard operator< of its element does?
I need to do it with predicates, because I need to sort the list with
different sorting criterions, depending on the situation.
Regards,
Matthias