summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/vector.hxx
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/lib/misc/vector.hxx
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/lib/misc/vector.hxx')
-rw-r--r--tiger-compiler/lib/misc/vector.hxx193
1 files changed, 193 insertions, 0 deletions
diff --git a/tiger-compiler/lib/misc/vector.hxx b/tiger-compiler/lib/misc/vector.hxx
new file mode 100644
index 0000000..5c516cb
--- /dev/null
+++ b/tiger-compiler/lib/misc/vector.hxx
@@ -0,0 +1,193 @@
+/** -*- C++ -*-
+ ** \file misc/vector.hxx
+ ** \brief Implementation of misc::vector.
+ */
+
+#pragma once
+
+#include <ostream>
+
+#include <misc/contract.hh>
+
+namespace misc
+{
+ template <class T> vector<T>::vector() {}
+
+ template <class T> vector<T>::vector(const T& t) { this->push_back(t); }
+
+ template <class T> vector<T>::vector(const T& t1, const T& t2)
+ {
+ this->push_back(t1);
+ this->push_back(t2);
+ }
+
+ template <class T> vector<T>::vector(const T& t, const vector<T>& v)
+ {
+ this->push_back(t);
+ this->insert(this->end(), v.begin(), v.end());
+ }
+
+ template <class T> vector<T>::vector(std::initializer_list<T> l)
+ {
+ this->insert(this->begin(), l.begin(), l.end());
+ }
+
+ template <class T>
+ template <class InputIterator>
+ vector<T>::vector(InputIterator b, InputIterator e)
+ : super_type(b, e)
+ {}
+
+ template <class T>
+ template <class C>
+ vector<T>::vector(const C& c)
+ : super_type(c.begin(), c.end())
+ {}
+
+ template <class T> bool vector<T>::has(const T& data) const
+ {
+ return std::ranges::find(*this, data) != this->end();
+ }
+
+ template <class T>
+ inline typename std::vector<T>::iterator
+ vector<T>::prepend(const vector<T>& v)
+ {
+ auto it = this->insert(this->begin(), v.begin(), v.end());
+ return it;
+ }
+
+ template <class T>
+ inline typename std::vector<T>::iterator
+ vector<T>::prepend(const vector<T>&& v)
+ {
+ auto it = this->insert(this->begin(), v.begin(), v.end());
+ return it;
+ }
+
+ template <class T>
+ inline typename std::vector<T>::iterator vector<T>::append(const vector<T>& v)
+ {
+ auto it = this->insert(this->end(), v.begin(), v.end());
+ return it;
+ }
+
+ template <class T>
+ inline typename std::vector<T>::iterator
+ vector<T>::append(const vector<T>&& v)
+ {
+ auto it = this->insert(this->end(), v.begin(), v.end());
+ return it;
+ }
+
+ template <class T>
+ inline vector<T> vector<T>::operator+(const vector<T>& v) const
+ {
+ vector<T> res = *this;
+ return res += v;
+ }
+
+ template <class T> inline vector<T>& vector<T>::operator+=(const vector<T>& v)
+ {
+ this->insert(this->end(), v.begin(), v.end());
+ return *this;
+ }
+
+ template <class T>
+ template <typename Iterator>
+ inline typename std::vector<T>::iterator
+ vector<T>::position_append(const vector<T>& v, Iterator it)
+ {
+ auto new_it = this->insert(it, v.begin(), v.end());
+ return new_it;
+ }
+
+ template <class T>
+ template <typename Iterator>
+ inline typename std::vector<T>::iterator
+ vector<T>::position_append(const vector<T>&& v, Iterator it)
+ {
+ auto new_it = this->insert(it, v.begin(), v.end());
+ return new_it;
+ }
+
+ template <class T> inline vector<T>& vector<T>::remove(const T& data)
+ {
+ precondition(has(data));
+ this->erase(std::ranges::find(*this, data));
+ return *this;
+ }
+
+ template <class T> std::ostream& vector<T>::dump(std::ostream& ostr) const
+ {
+ for (typename super_type::const_iterator i = this->begin();
+ i != this->end(); ++i)
+ ostr << (i == this->begin() ? "" : ", ") << *i;
+ return ostr;
+ }
+
+ template <class T>
+ std::ostream& operator<<(std::ostream& ostr, const vector<T>& v)
+ {
+ return v.dump(ostr);
+ }
+
+ template <typename T>
+ auto append_and_move(std::vector<T>& v1, std::vector<T>&& v2)
+ {
+ auto it = v1.insert(v1.end(), make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+ template <typename T>
+ auto append_and_move(std::vector<T>& v1, std::vector<T>& v2)
+ {
+ auto it = v1.insert(v1.end(), make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+ template <typename T>
+ auto prepend_and_move(std::vector<T>& v1, std::vector<T>&& v2)
+ {
+ auto it = v1.insert(v1.begin(), make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+ template <typename T>
+ auto prepend_and_move(std::vector<T>& v1, std::vector<T>& v2)
+ {
+ auto it = v1.insert(v1.begin(), make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+ template <typename T, typename Iterator>
+ auto position_append_and_move(std::vector<T>& v1,
+ Iterator v1_iterator,
+ std::vector<T>&& v2)
+ {
+ auto it = v1.insert(v1_iterator, make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+ template <typename T, typename Iterator>
+ auto position_append_and_move(std::vector<T>& v1,
+ Iterator v1_iterator,
+ std::vector<T>& v2)
+ {
+ auto it = v1.insert(v1_iterator, make_move_iterator(v2.begin()),
+ make_move_iterator(v2.end()));
+ v2.clear();
+ return it;
+ }
+
+} // namespace misc