Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_set.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_SET_HPP
11 #define TEUCHOS_SET_HPP
12 
13 #include <set>
14 #include <iosfwd>
15 #include <Teuchos_Assert.hpp>
16 
17 namespace Teuchos {
18 
19 template <typename T>
20 void unite_with(std::set<T>& a, std::set<T> const& b) {
21  for (typename std::set<T>::const_iterator it = b.begin(); it != b.end(); ++it) {
22  const T& x = *it;
23  a.insert(x);
24  }
25 }
26 
27 template <typename T>
28 void unite(std::set<T>& result, std::set<T> const& a, std::set<T> const& b) {
29  result = a;
30  unite_with(result, b);
31 }
32 
33 template <typename T>
34 void subtract_from(std::set<T>& a, std::set<T> const& b) {
35  for (typename std::set<T>::const_iterator it = b.begin(); it != b.end(); ++it) {
36  const T& x = *it;
37  typename std::set<T>::iterator it2 = a.find(x);
38  if (it2 == a.end()) continue;
39  a.erase(it2);
40  }
41 }
42 
43 template <typename T>
44 bool intersects(std::set<T> const& a, std::set<T> const& b) {
45  for (typename std::set<T>::const_iterator it = b.begin(); it != b.end(); ++it) {
46  const T& x = *it;
47  typename std::set<T>::const_iterator it2 = a.find(x);
48  if (it2 != a.end()) return true;
49  }
50  return false;
51 }
52 
53 }
54 
55 #endif