63 typedef const T *value_type;
70 explicit Vector(
const T *a) { vec.emplace_back(std::move(a)); }
72 Vector(std::initializer_list<const T *> a) : vec(a) {}
73 template <
class InputIt>
74 Vector(InputIt first, InputIt last) : vec(first, last) {}
76 : vec(e->begin(), e->end()) {}
78 typedef typename safe_vector<const T *>::iterator iterator;
79 typedef typename safe_vector<const T *>::const_iterator const_iterator;
80 iterator begin() {
return vec.begin(); }
81 const_iterator begin()
const {
return vec.begin(); }
82 VectorBase::iterator VectorBase_begin()
const override {
84 return reinterpret_cast<VectorBase::iterator
>(&vec[0]);
86 iterator end() {
return vec.end(); }
87 const_iterator end()
const {
return vec.end(); }
88 VectorBase::iterator VectorBase_end()
const override {
90 return reinterpret_cast<VectorBase::iterator
>(&vec[0] + vec.size());
92 std::reverse_iterator<iterator> rbegin() {
return vec.rbegin(); }
93 std::reverse_iterator<const_iterator> rbegin()
const {
return vec.rbegin(); }
94 std::reverse_iterator<iterator> rend() {
return vec.rend(); }
95 std::reverse_iterator<const_iterator> rend()
const {
return vec.rend(); }
96 size_t size()
const override {
return vec.size(); }
97 void resize(
size_t sz) { vec.resize(sz); }
98 bool empty()
const override {
return vec.empty(); }
99 const T *
const &front()
const {
return vec.front(); }
100 const T *&front() {
return vec.front(); }
101 void clear() { vec.clear(); }
102 iterator erase(iterator i) {
return vec.erase(i); }
103 iterator erase(iterator s, iterator e) {
return vec.erase(s, e); }
104 template <
typename ForwardIter>
105 iterator insert(iterator i, ForwardIter b, ForwardIter e) {
108 int index = i - vec.begin();
110 return vec.begin() + index;
113 template <
typename Container>
114 iterator append(
const Container &toAppend) {
115 return insert(end(), toAppend.begin(), toAppend.end());
117 template <
typename Container>
118 iterator prepend(
const Container &toAppend) {
119 return insert(begin(), toAppend.begin(), toAppend.end());
129 if (item ==
nullptr)
return;
131 append(*itemAsVector);
134 BUG_CHECK(item->
is<T>(),
"Unexpected vector element: %1%", item);
135 push_back(item->
to<T>());
138 iterator insert(iterator i,
const T *v) {
141 int index = i - vec.begin();
143 return vec.begin() + index;
145 iterator insert(iterator i,
size_t n,
const T *v) {
148 int index = i - vec.begin();
150 return vec.begin() + index;
153 const T *
const &operator[](
size_t idx)
const {
return vec[idx]; }
154 const T *&operator[](
size_t idx) {
return vec[idx]; }
155 const T *
const &at(
size_t idx)
const {
return vec.at(idx); }
156 const T *&at(
size_t idx) {
return vec.at(idx); }
157 template <
class... Args>
158 void emplace_back(Args &&...args) {
159 vec.emplace_back(
new T(std::forward<Args>(args)...));
161 void push_back(T *a) { vec.push_back(a); }
162 void push_back(
const T *a) { vec.push_back(a); }
163 void pop_back() { vec.pop_back(); }
164 const T *
const &back()
const {
return vec.back(); }
165 const T *&back() {
return vec.back(); }
167 void push_back(U &a) {
170 void check_null()
const {
171 for (
auto e : vec) CHECK_NULL(e);
174 IRNODE_SUBCLASS(Vector)
175 IRNODE_DECLARE_APPLY_OVERLOAD(Vector)
176 bool operator==(
const Node &a)
const override {
return a == *
this; }
177 bool operator==(
const Vector &a)
const override {
return vec == a.vec; }
192 bool equiv(
const Node &a_)
const override {
193 if (
static_cast<const Node *
>(
this) == &a_)
return true;
194 if (this->
typeId() != a_.typeId())
return false;
195 auto &a =
static_cast<const Vector<T> &
>(a_);
196 if (size() != a.size())
return false;
198 for (
auto *el : *
this)
199 if (!el->equiv(**it++))
return false;
202 cstring node_type_name()
const override {
return "Vector<" + T::static_type_name() +
">"; }
203 static cstring static_type_name() {
return "Vector<" + T::static_type_name() +
">"; }
204 void visit_children(Visitor &v)
override;
205 void visit_children(Visitor &v)
const override;
206 virtual void parallel_visit_children(Visitor &v);
207 virtual void parallel_visit_children(Visitor &v)
const;
208 void toJSON(JSONGenerator &json)
const override;
209 Util::Enumerator<const T *> *getEnumerator()
const {
return Util::enumerate(vec); }
210 template <
typename S>
211 Util::Enumerator<const S *> *only()
const {
213 [](
const T *d) {
return d !=
nullptr; });
215 template <
class Filter>
216 auto where(Filter f)
const {
217 return getEnumerator()->where(std::move(f));
220 void dbprint(std::ostream &out)
const override {
221 out <<
"{" << IndentCtl::indent;
222 for (
auto p : *
this) {
225 out << IndentCtl::unindent <<
" }";
228 DECLARE_TYPEINFO_WITH_DISCRIMINATOR(Vector<T>, NodeDiscriminator::VectorT, T, VectorBase);