Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » operator< for container sorting (small confusion)
icon5.gif  operator< for container sorting (small confusion) [message #13071] Sat, 08 December 2007 20:10 Go to next message
Andy2222 is currently offline  Andy2222
Messages: 4
Registered: December 2007
Junior Member
I'm trying to store my own data type inside a Index<> so far i made it "movable" and it has the needed hashing call and a == operator.

Im just not sure how can i sort the Index using the Sort() function?

I saw some examples where the global operator< is overloaded by like this.

bool operator<(const XDCCPackage& a, const XDCCPackage& b)
{
return a.Filename < b.Filename;
}

So i don't define one inside the class and overload the global operator<?

I tryed doing this but it seem also need to define the operator= or a swap call?
Little confused right now small hints pls?


PS: is there a U++ nooby section? Smile

[Updated on: Sat, 08 December 2007 20:10]

Report message to a moderator

Re: operator< for container sorting (small confusion) [message #13073 is a reply to message #13071] Sun, 09 December 2007 07:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Andy2222 wrote on Sat, 08 December 2007 14:10

I'm trying to store my own data type inside a Index<> so far i made it "movable" and it has the needed hashing call and a == operator.

Im just not sure how can i sort the Index using the Sort() function?

I saw some examples where the global operator< is overloaded by like this.

bool operator<(const XDCCPackage& a, const XDCCPackage& b)
{
return a.Filename < b.Filename;
}

So i don't define one inside the class and overload the global operator<?

I tryed doing this but it seem also need to define the operator= or a swap call?
Little confused right now small hints pls?


PS: is there a U++ nooby section? Smile


Well, it can be global, but IMO the main problem is that you cannot Sort Index (that is that missing Swap).

If you really need to sort Index, convert it to Vector, sort and convert back.

(Use PickKeys to convert to Vector and constructor variant for conversion back).

Mirek
Re: operator< for container sorting (small confusion) [message #13080 is a reply to message #13073] Sun, 09 December 2007 14:48 Go to previous messageGo to next message
Andy2222 is currently offline  Andy2222
Messages: 4
Registered: December 2007
Junior Member
ah oki,

is there a std::map<> equivalent container?
Or do i call Sort on Vector<> / Array<> before i need it sorted or use the GetSortOrder() call?
Re: operator< for container sorting (small confusion) [message #13081 is a reply to message #13080] Sun, 09 December 2007 16:18 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Andy2222 wrote on Sun, 09 December 2007 08:48

ah oki,

is there a std::map<> equivalent container?



No.

Quote:


Or do i call Sort on Vector<> / Array<> before i need it sorted or use the GetSortOrder() call?


In most cases, GetSortOrder for Index / ArrayMap / VectorMap is the best aproach (also generally faster than the cost of maintaining nodebased tree structure like std::map).

Mirek
Previous Topic: <<= and <<
Next Topic: A couple of issues with a test app
Goto Forum:
  


Current Time: Thu Mar 28 20:48:07 CET 2024

Total time taken to generate the page: 0.01468 seconds