P4C
The P4 Compiler
Loading...
Searching...
No Matches
set.h
1#ifndef LIB_SET_H_
2#define LIB_SET_H_
3
4#include <set>
5
6/* stuff that should be in std::set but is missing... */
7
8template <class T, class C1, class A1, class U>
9inline auto operator|=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
10 for (auto &el : b) a.insert(el);
11 return a;
12}
13template <class T, class C1, class A1, class U>
14inline auto operator-=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
15 for (auto &el : b) a.erase(el);
16 return a;
17}
18template <class T, class C1, class A1, class U>
19inline auto operator&=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
20 for (auto it = a.begin(); it != a.end();) {
21 if (b.count(*it))
22 ++it;
23 else
24 it = a.erase(it);
25 }
26 return a;
27}
28
29template <class T, class C1, class A1, class U>
30inline auto contains(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
31 for (auto &el : b)
32 if (!a.count(el)) return false;
33 return true;
34}
35template <class T, class C1, class A1, class U>
36inline auto intersects(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
37 for (auto &el : b)
38 if (a.count(el)) return true;
39 return false;
40}
41
42#endif /* LIB_SET_H_ */