// (C) Copyright Jeremy Siek 2001. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_SET_ADAPTOR_HPP #define BOOST_SET_ADAPTOR_HPP #include #include namespace boost { template bool set_contains(const std::set& s, const T& x) { return s.find(x) != s.end(); } template bool set_contains(const boost::unordered_set& s, const T& x) { return s.find(x) != s.end(); } template bool set_equal(const std::set& x, const std::set& y) { return x == y; } // Not the same as lexicographical_compare_3way applied to std::set. // this is equivalent semantically to bitset::operator<() template int set_lex_order(const std::set& x, const std::set& y) { typename std::set::iterator xi = x.begin(), yi = y.begin(), xend = x.end(), yend = y.end(); for (; xi != xend && yi != yend; ++xi, ++yi) { if (*xi < *yi) return 1; else if (*yi < *xi) return -1; } if (xi == xend) return (yi == yend) ? 0 : -1; else return 1; } template void set_clear(std::set& x) { x.clear(); } template bool set_empty(const std::set& x) { return x.empty(); } template void set_insert(std::set& x, const T& a) { x.insert(a); } template void set_remove(std::set& x, const T& a) { x.erase(a); } template void set_intersect(const std::set& x, const std::set& y, std::set& z) { z.clear(); std::set_intersection(x.begin(), x.end(), y.begin(), y.end(), std::inserter(z)); } template void set_union(const std::set& x, const std::set& y, std::set& z) { z.clear(); std::set_union(x.begin(), x.end(), y.begin(), y.end(), std::inserter(z)); } template void set_difference(const std::set& x, const std::set& y, std::set& z) { z.clear(); std::set_difference(x.begin(), x.end(), y.begin(), y.end(), std::inserter(z, z.begin())); } template bool set_subset(const std::set& x, const std::set& y) { return std::includes(x.begin(), x.end(), y.begin(), y.end()); } // Shit, can't implement this without knowing the size of the // universe. template void set_compliment(const std::set& /*x*/, std::set& z) { z.clear(); } } // namespace boost #endif // BOOST_SET_ADAPTOR_HPP