From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/set.hh | 146 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 tiger-compiler/lib/misc/set.hh (limited to 'tiger-compiler/lib/misc/set.hh') diff --git a/tiger-compiler/lib/misc/set.hh b/tiger-compiler/lib/misc/set.hh new file mode 100644 index 0000000..5ded61b --- /dev/null +++ b/tiger-compiler/lib/misc/set.hh @@ -0,0 +1,146 @@ +/** + ** \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 -- cgit v1.2.3