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/vector.hh | 105 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tiger-compiler/lib/misc/vector.hh (limited to 'tiger-compiler/lib/misc/vector.hh') diff --git a/tiger-compiler/lib/misc/vector.hh b/tiger-compiler/lib/misc/vector.hh new file mode 100644 index 0000000..2207552 --- /dev/null +++ b/tiger-compiler/lib/misc/vector.hh @@ -0,0 +1,105 @@ +/** + ** \file misc/vector.hh + ** \brief Declaration of misc::vector + */ + +#pragma once + +#include +#include +#include + +namespace misc +{ + template class vector : public std::vector + { + public: + /// Super class type. + using super_type = std::vector; + + /// \name Constructors and destructor. + /// \{ + /// Build an empty vector. + vector(); + + /// Build a one-element vector. + vector(const Ident_& t); + + /// Build a two-element vector. + vector(const Ident_& t1, const Ident_& t2); + + /// Concat an element and a vector. + vector(const Ident_& t, const vector& v); + + // Build a vector from an initializer list. + vector(std::initializer_list l); + + /// Build a vector from 2 iterators. + template vector(InputIterator b, InputIterator e); + + /// Build a vector fro, another container. + template vector(const C& c); + /// \} + + /// \name Content management. + /// \{ + /// Is \a data part of \a this vector? + bool has(const Ident_& data) const; + + /// Prepend \a v into \a this and return the new iterator. + typename super_type::iterator prepend(const vector& v); + typename super_type::iterator prepend(const vector&& v); + + /// Append \a v into \a this and return the new iterator. + typename super_type::iterator append(const vector& v); + typename super_type::iterator append(const vector&& v); + + /// Append \a v into \a this. + vector operator+(const vector& v) const; + /// Append \a v into \a this. + vector& operator+=(const vector& v); + + /// Append \a v into \a this from it and return the new iterator. + template + typename super_type::iterator position_append(const vector& v, Iterator it); + template + typename super_type::iterator position_append(const vector&& v, + Iterator it); + + /** \brief Remove \a data from \a this. + \a data must be part of \a this. */ + vector& remove(const Ident_& data); + /// \} + + virtual std::ostream& dump(std::ostream& ostr) const; + }; + + /// Output \a v onto \a ostr. + template + std::ostream& operator<<(std::ostream& ostr, const vector& v); + + template + auto append_and_move(std::vector& res, std::vector&& to_append); + + template + auto append_and_move(std::vector& res, std::vector& to_append); + + template + auto prepend_and_move(std::vector& res, std::vector&& to_prepend); + + template + auto prepend_and_move(std::vector& res, std::vector& to_prepend); + + template + auto position_append_and_move(std::vector& res, + Iterator res_iterator, + std::vector&& to_append); + + template + auto position_append_and_move(std::vector& res, + Iterator res_iterator, + std::vector& to_append); + +} // namespace misc + +#include -- cgit v1.2.3