/** ** \file misc/set.hh ** \brief misc::set: wrapper around std::set. ** ** Set class is a std::set wrapper used to facilitate set ** operations such as '+' (union) and '-' and also redefine ** functions such as set_union, set_intersection etc. in ** order to be more specific and more simple to handle set for our ** purpose. **/ #pragma once #include #include #include #include #include namespace misc { template , typename Allocator = std::allocator> /** ** \brief The class misc::set is wrapper around std::set. ** ** Because Doxygen doesn't handle template ** parameters names mix we keep the shorter version, ** so K for Key, C for Compare and A for Allocator. */ class set : public std::set { public: /// \name typedefs /// \{ using set_type = typename std::set; using iterator = typename set_type::iterator; using const_iterator = typename set_type::const_iterator; using reverse_iterator = typename set_type::reverse_iterator; using const_reverse_iterator = typename set_type::const_reverse_iterator; using size_type = typename set_type::size_type; using const_reference = typename set_type::const_reference; /// \} /// \name constructor(s)/destructor. /// \{ explicit set() = default; template requires Iterator explicit set(Iter first, Iter last); /* Useful to convert a container (e.g. std::vector) in misc::set. */ template requires ConstIterableType explicit set(const Container v); /// \} /** \name Element vs. set. \{ */ /// Is \a k part of \a this set? bool has(const Key& k) const; /** \brief Return the addition of \a data into \a this. \a data must not yet be part of \a this. */ set operator+(const Key& data) const; /** \brief Insert \a data in \a this. \a data must not yet be part of \a this. */ set& operator+=(const Key& data); /** \brief Return the removal of \a data into \a this. \a data must be part of \a this. */ set operator-(const Key& data) const; /** \brief Remove \a data from \a this. \a data must be part of \a this. */ set& operator-=(const Key& data); /// \} /** \name Set vs. set. \{ */ /// Union with another set \a s. // FIXME: Deprecate this use, it ought to be direct sum. set operator+(const set& s) const; /// In place union with another set \a s. set& operator+=(const set& s); /// Subtraction with another set \a s. set operator-(const set& s) const; /// In place subtraction with another set \a s. set& operator-=(const set& s); /// Union with another set \a s. set operator|(const set& s) const; /// In place union with another set \a s. set& operator|=(const set& s); /// Intersection with another set \a s. set operator&(const set& s) const; /// In place intersection with another set \a s. set& operator&=(const set& s); /// \} }; // class set template inline set set_difference(const set& s1, const set& s2); template inline set set_intersection(const set& s1, const set& s2); template inline set set_union(const set& s1, const set& s2); /* Print a human-dump for debugging. Warning: this method requires that type Key overloads the operator '<<'. If it is not the case do it or remove set print method and << operator (see below). */ template inline std::ostream& operator<<(std::ostream& ostr, const set& s); template inline bool operator%(const Key& k, const set& s); } // namespace misc #include