P4C
The P4 Compiler
Loading...
Searching...
No Matches
set.h
1/*
2 * SPDX-FileCopyrightText: 2016 Barefoot Networks, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef LIB_SET_H_
8#define LIB_SET_H_
9
10#include <set>
11
12/* stuff that should be in std::set but is missing... */
13namespace P4 {
14
15template <class T, class C1, class A1, class U>
16inline auto operator|=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
17 for (auto &el : b) a.insert(el);
18 return a;
19}
20template <class T, class C1, class A1, class U>
21inline auto operator-=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
22 for (auto &el : b) a.erase(el);
23 return a;
24}
25template <class T, class C1, class A1, class U>
26inline auto operator&=(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), a) {
27 for (auto it = a.begin(); it != a.end();) {
28 if (b.count(*it))
29 ++it;
30 else
31 it = a.erase(it);
32 }
33 return a;
34}
35
36template <class T, class C1, class A1, class U>
37inline auto contains(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
38 for (auto &el : b)
39 if (!a.count(el)) return false;
40 return true;
41}
42template <class T, class C1, class A1, class U>
43inline auto intersects(std::set<T, C1, A1> &a, U &b) -> decltype(b.begin(), true) {
44 for (auto &el : b)
45 if (a.count(el)) return true;
46 return false;
47}
48
49} // namespace P4
50
51#endif /* LIB_SET_H_ */
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13