summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/vector.hh
blob: 22075522ba47394bf7b1ec5eb95103d50fb48f98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
 ** \file misc/vector.hh
 ** \brief Declaration of misc::vector
 */

#pragma once

#include <algorithm>
#include <iosfwd>
#include <vector>

namespace misc
{
  template <class Ident_> class vector : public std::vector<Ident_>
  {
  public:
    /// Super class type.
    using super_type = std::vector<Ident_>;

    /// \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<Ident_> l);

    /// Build a vector from 2 iterators.
    template <class InputIterator> vector(InputIterator b, InputIterator e);

    /// Build a vector fro, another container.
    template <class C> 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<Ident_>& v);
    typename super_type::iterator prepend(const vector<Ident_>&& v);

    /// Append \a v into \a this and return the new iterator.
    typename super_type::iterator append(const vector<Ident_>& v);
    typename super_type::iterator append(const vector<Ident_>&& 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 Iterator>
    typename super_type::iterator position_append(const vector& v, Iterator it);
    template <typename Iterator>
    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 <class Ident_>
  std::ostream& operator<<(std::ostream& ostr, const vector<Ident_>& v);

  template <typename T>
  auto append_and_move(std::vector<T>& res, std::vector<T>&& to_append);

  template <typename T>
  auto append_and_move(std::vector<T>& res, std::vector<T>& to_append);

  template <typename T>
  auto prepend_and_move(std::vector<T>& res, std::vector<T>&& to_prepend);

  template <typename T>
  auto prepend_and_move(std::vector<T>& res, std::vector<T>& to_prepend);

  template <typename T, typename Iterator>
  auto position_append_and_move(std::vector<T>& res,
                                Iterator res_iterator,
                                std::vector<T>&& to_append);

  template <typename T, typename Iterator>
  auto position_append_and_move(std::vector<T>& res,
                                Iterator res_iterator,
                                std::vector<T>& to_append);

} // namespace misc

#include <misc/vector.hxx>