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... */
7namespace P4 {
8
9template <class T, class C1, class A1, class U>
10inline auto operator|=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
11 for (auto &el : b) a.insert(el);
12 return a;
13}
14template <class T, class C1, class A1, class U>
15inline auto operator-=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
16 for (auto &el : b) a.erase(el);
17 return a;
18}
19template <class T, class C1, class A1, class U>
20inline auto operator&=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
21 for (auto it = a.begin(); it != a.end();) {
22 if (b.count(*it))
23 ++it;
24 else
25 it = a.erase(it);
26 }
27 return a;
28}
29
30template <class T, class C1, class A1, class U>
31inline auto contains(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
32 for (auto &el : b)
33 if (!a.count(el)) return false;
34 return true;
35}
36template <class T, class C1, class A1, class U>
37inline auto intersects(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
38 for (auto &el : b)
39 if (a.count(el)) return true;
40 return false;
41}
42
43} // namespace P4
44
45#endif /* LIB_SET_H_ */
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24