Apache Mesos
set.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_SET_HPP__
14 #define __STOUT_SET_HPP__
15 
16 #include <algorithm> // For std::set_intersection.
17 #include <set>
18 
19 template <typename T>
20 std::set<T> operator|(const std::set<T>& left, const std::set<T>& right)
21 {
22  // Note, we're not using 'set_union' since it affords us no benefit
23  // in efficiency and is more complicated to use given we have sets.
24  std::set<T> result = left;
25  result.insert(right.begin(), right.end());
26  return result;
27 }
28 
29 
30 template <typename T>
31 std::set<T> operator+(const std::set<T>& left, const T& t)
32 {
33  std::set<T> result = left;
34  result.insert(t);
35  return result;
36 }
37 
38 
39 template <typename T>
40 std::set<T> operator&(const std::set<T>& left, const std::set<T>& right)
41 {
42  std::set<T> result;
43  std::set_intersection(
44  left.begin(),
45  left.end(),
46  right.begin(),
47  right.end(),
48  std::inserter(result, result.begin()));
49  return result;
50 }
51 
52 #endif // __STOUT_SET_HPP__
std::set< T > operator+(const std::set< T > &left, const T &t)
Definition: set.hpp:31
std::set< T > operator|(const std::set< T > &left, const std::set< T > &right)
Definition: set.hpp:20
std::set< T > operator&(const std::set< T > &left, const std::set< T > &right)
Definition: set.hpp:40