set question

Can we use set data structure with pair of values? If yes, how would the values be sorted? Would it be sorted based on first value in the pair?
Can someone please reply on this?
Last edited on
> Can we use set data structure with pair of values?

Yes.

> If yes, how would the values be sorted?

If we don't provide a predicate to compare pairs, the members of the pair must be LessThanComparable, and the overloaded operator< for std::pair would be used. Which
Compares lhs and rhs lexicographically, that is, compares the first elements and only if they are equivalent, compares the second elements. http://en.cppreference.com/w/cpp/utility/pair/operator_cmp
Thanks @JLBorges, thats very helpful.
Topic archived. No new replies allowed.