Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Setting predica...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 43983 of 48044
Post > Topic >>

Setting predicate for std::list::sort().

by "jason.cipriani@[EMAIL PROTECTED] " <jason.cipriani@[EMAIL PROTECTED] > Mar 18, 2008 at 02:55 PM

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
 




 5 Posts in Topic:
Setting predicate for std::list::sort().
"jason.cipriani@[EMA  2008-03-18 14:55:52 
Re: Setting predicate for std::list::sort().
"Victor Bazarov"  2008-03-18 18:01:45 
Re: Setting predicate for std::list::sort().
red floyd <no.spam@[EM  2008-03-18 15:01:59 
Re: Setting predicate for std::list::sort().
red floyd <no.spam@[EM  2008-03-18 15:11:53 
Re: Setting predicate for std::list::sort().
"jason.cipriani@[EMA  2008-03-18 16:34:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:40:20 CDT 2008.