set question

Oct 18, 2016 at 1:50am
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?
Oct 18, 2016 at 3:55am
Can someone please reply on this?
Last edited on Oct 18, 2016 at 3:55am
Oct 18, 2016 at 4:05am
> 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
Oct 19, 2016 at 1:23am
Thanks @JLBorges, thats very helpful.
Topic archived. No new replies allowed.