mardi 3 novembre 2015

Do C++ unordered_sets have easy boolean operations? (intersect, union, difference)

I've searched all over, but I can't find any way to easily perform boolean operations between unordered_sets in c++. I've read about set_intersection, but that only works on ordered sets.

This is incredibly easy in something like Python:

a = set([1, 2, 3, 4])
b = set([2, 4])
>>> a.difference(b)
   set([1, 3])
>>> a.intersection(b)
   set([2, 4])
>>> a.union(b)
   set([1, 2, 3, 4])

I have trouble believing that between C++11 and boost, there's no clean way of doing this without writing your own functions.

Am I missing something?

Aucun commentaire:

Enregistrer un commentaire