Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Multipmap of pointers, sort by key

Reply
Thread Tools

Multipmap of pointers, sort by key

 
 
Roland Pibinger
Guest
Posts: n/a
 
      04-11-2007
On 11 Apr 2007 07:58:09 -0700, "karen.b.lin@...com" wrote:

>But still don't get why overloading () ?


It's just a requirement of the STL. Alternatively the function might
have been called 'compare' or something like that. The advantage of
the STL solution is that you can use as predicate a free function and
an object with operator() alike.


--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
 
Reply With Quote
 
 
 
 
karen.b.lin@gmail.com
Guest
Posts: n/a
 
      04-13-2007
Thank u all for the replies. Just want to further perfect my codes,
if i want to sort first by the key, then by value. How will i specify
it in my sorter, something like this? not sure where do i put the
value type in the sorter?

key: BOMBImntRT*
value: BOMBPortfolio*

struct UnderlyingsPtrSorter
{
bool operator() (const BOMBImntRT* a, const BOMBImntRT* b) const{
if(a->ImntName == b->ImntName)
//??
else
return a->ImntName < b->ImntName;
}
};

 
Reply With Quote
 
 
 
 
xperthands
Guest
Posts: n/a
 
      04-13-2007
On Apr 13, 9:03 am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Thank u all for the replies. Just want to further perfect my codes,
> if i want to sort first by the key, then by value. How will i specify
> it in my sorter, something like this? not sure where do i put the
> value type in the sorter?


You don't. Only the key will be passed to the predicate. If you want
the
value to be considered you should use std::set<T> and have the key
part
of the type you specify for T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
another way to sort like l.sort(key=lambda x:(x[0][0], -x[1][0])) sajuptpm Python 7 09-08-2010 06:55 PM
Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute cjt22@bath.ac.uk Python 7 09-10-2007 11:10 AM
xsl:sort using an xsl:variable as the sort key jobooker@gmail.com XML 2 09-05-2006 03:51 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM
sort multi-key hash by value and print out with key value pairs Antonio Quinonez Perl Misc 2 08-14-2003 10:56 PM



Advertisments