Math Library / Title

In which library / title (if any) is the math set? I need to set functions like intersection, union, etc.

+3
source share
6 answers

Use <set>and <algorithm>.

Then std provides std::set_union, std::set_intersectionetc.

Example:

#include <set>
#include <algorithm>

 ...
std::set<int> s1, s2;
for(int i = 0; i < 20; ++i)  s1.insert(i);
for(int i = 10; i < 30; ++i) s2.insert(i);
std::set<int> my_union, my_intersection;
std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(my_union, my_union.begin()));
std::set_interesction(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(my_intersection, my_intersection.begin()));
+5
source

You can use std::set( <set>) for dialing and std::set_intersectionand std::set_union( <algorithm>) for that.

+6
source
+3

<algorithm>

· set_difference
· set_intersection
· set_symmetric_difference
· set_union
+2

#include <set>
#include <algorithm>
0

You can try https://github.com/aseprano/Set , it provides what you are looking for. Do not use std :: set or any other stl container, as they do not have full support for math sets.

0
source

Source: https://habr.com/ru/post/1786888/


All Articles