source: NonGTP/Boost/boost/graph/detail/set_adaptor.hpp @ 857

Revision 857, 3.3 KB checked in by igarcia, 18 years ago (diff)
Line 
1// (C) Copyright Jeremy Siek 2001.
2// Distributed under the Boost Software License, Version 1.0. (See
3// accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_SET_ADAPTOR_HPP
7#define BOOST_SET_ADAPTOR_HPP
8
9#include <set>
10
11namespace boost {
12
13    template <class K, class C, class A, class T>
14    bool set_contains(const std::set<K,C,A>& s, const T& x) {
15      return s.find(x) != s.end();
16    }
17   
18    template <class K, class C, class A>
19    bool set_equal(const std::set<K,C,A>& x,
20                   const std::set<K,C,A>& y)
21    {
22      return x == y;
23    }
24
25    // Not the same as lexicographical_compare_3way applied to std::set.
26    // this is equivalent semantically to bitset::operator<()
27    template <class K, class C, class A>
28    int set_lex_order(const std::set<K,C,A>& x,
29                      const std::set<K,C,A>& y)
30    {
31      typename std::set<K,C,A>::iterator
32        xi = x.begin(), yi = y.begin(), xend = x.end(), yend = y.end();
33      for (; xi != xend && yi != yend; ++xi, ++yi) {
34        if (*xi < *yi)
35          return 1;
36        else if (*yi < *xi)
37          return -1;
38      }
39      if (xi == xend)
40        return (yi == yend) ? 0 : -1;
41      else
42        return 1;
43    }
44
45    template <class K, class C, class A>
46    void set_clear(std::set<K,C,A>& x) {
47      x.clear();
48    }
49
50    template <class K, class C, class A>
51    bool set_empty(const std::set<K,C,A>& x) {
52      return x.empty();
53    }
54
55    template <class K, class C, class A, class T>
56    void set_insert(std::set<K,C,A>& x, const T& a) {
57      x.insert(a);
58    }
59
60    template <class K, class C, class A, class T>
61    void set_remove(std::set<K,C,A>& x, const T& a) {
62      x.erase(a);
63    }
64   
65    template <class K, class C, class A>
66    void set_intersect(const std::set<K,C,A>& x,
67                       const std::set<K,C,A>& y,
68                       std::set<K,C,A>& z)
69    {
70      z.clear();
71      std::set_intersection(x.begin(), x.end(),
72                            y.begin(), y.end(),
73                            std::inserter(z));
74    }
75
76    template <class K, class C, class A>
77    void set_union(const std::set<K,C,A>& x,
78                   const std::set<K,C,A>& y,
79                   std::set<K,C,A>& z)
80    {
81      z.clear();
82      std::set_union(x.begin(), x.end(),
83                     y.begin(), y.end(),
84                     std::inserter(z));
85    }
86
87    template <class K, class C, class A>
88    void set_difference(const std::set<K,C,A>& x,
89                        const std::set<K,C,A>& y,
90                        std::set<K,C,A>& z)
91    {
92      z.clear();
93      std::set_difference(x.begin(), x.end(),
94                          y.begin(), y.end(),
95                          std::inserter(z, z.begin()));
96    }
97
98    template <class K, class C, class A>
99    bool set_subset(const std::set<K,C,A>& x,
100                    const std::set<K,C,A>& y)
101    {
102      return std::includes(x.begin(), x.end(), y.begin(), y.end());
103    }
104
105    // Shit, can't implement this without knowing the size of the
106    // universe.
107    template <class K, class C, class A>
108    void set_compliment(const std::set<K,C,A>& x,
109                        std::set<K,C,A>& z)
110    {
111      z.clear();
112     
113    }
114   
115} // namespace boost   
116
117#endif // BOOST_SET_ADAPTOR_HPP
Note: See TracBrowser for help on using the repository browser.