forked from p4lang/p4c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset.h
45 lines (39 loc) · 1.22 KB
/
set.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef LIB_SET_H_
#define LIB_SET_H_
#include <set>
/* stuff that should be in std::set but is missing... */
namespace P4 {
template <class T, class C1, class A1, class U>
inline auto operator|=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
for (auto &el : b) a.insert(el);
return a;
}
template <class T, class C1, class A1, class U>
inline auto operator-=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
for (auto &el : b) a.erase(el);
return a;
}
template <class T, class C1, class A1, class U>
inline auto operator&=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
for (auto it = a.begin(); it != a.end();) {
if (b.count(*it))
++it;
else
it = a.erase(it);
}
return a;
}
template <class T, class C1, class A1, class U>
inline auto contains(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
for (auto &el : b)
if (!a.count(el)) return false;
return true;
}
template <class T, class C1, class A1, class U>
inline auto intersects(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
for (auto &el : b)
if (a.count(el)) return true;
return false;
}
} // namespace P4
#endif /* LIB_SET_H_ */