Sign in to follow this  
MARS_999

std::sort with std::pair in a std::vector

Recommended Posts

[code]
std::vector<std::pair<int, int*>> temp;
std::pair<int, int*> pair;
//add to pair here
temp.push_back(pair);
std::sort(temp.begin(), temp.end());
[/code]

I am guessing this code works and will sort the temp vector and not hidden gotchas? I just need the pointers sorted based on some priority value

Thanks

Share this post


Link to post
Share on other sites
It will sort the pairs sorted first by the first element of each pair and then the value of the pointer in case of ties.

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1343008304' post='4962107']
It will sort the pairs sorted first by the first element of each pair and then the value of the pointer in case of ties.
[/quote]

Thanks for the help SiCrane. Should work for what I need.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this