Sign in to follow this  

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

This topic is 1967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
[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

This topic is 1967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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