Getting connection, intersection or difference sets in C ++

I have a couple of questions on how to use C ++ sets (std :: set)

  • Is there a way to get the union, intersection, or difference of two sets of C ++? (It's pretty easy to write my own function to do this, but I wanted to know if there was a built-in function for it)

  • Can a C ++ set be used as keys on a map?

+6
c ++ set unions map intersection
source share
3 answers

Use the set_difference() , set_union() , set_intersection() and set_symmetric_difference() functions.

Kits and cards support any type of key that can match. By default, this means that the type has operator<() , but you can provide your own comparator. C ++ sets do not have operator<() and cannot be used as keys unless you provide your own comparator.

+16
source share

Regarding your first question, take a look

+9
source share

Everything that can be used as a key on the map, as long as you provide a class or function that can compare them. Here is an example .

+3
source share

All Articles