60 typedef const T *value_type;
67 explicit Vector(
const T *a) { vec.emplace_back(std::move(a)); }
69 Vector(
const std::initializer_list<const T *> &a) : vec(a) {}
71 typedef typename safe_vector<const T *>::iterator iterator;
72 typedef typename safe_vector<const T *>::const_iterator const_iterator;
73 iterator begin() {
return vec.begin(); }
74 const_iterator begin()
const {
return vec.begin(); }
75 VectorBase::iterator VectorBase_begin()
const override {
77 return reinterpret_cast<VectorBase::iterator
>(&vec[0]);
79 iterator end() {
return vec.end(); }
80 const_iterator end()
const {
return vec.end(); }
81 VectorBase::iterator VectorBase_end()
const override {
83 return reinterpret_cast<VectorBase::iterator
>(&vec[0] + vec.size());
85 std::reverse_iterator<iterator> rbegin() {
return vec.rbegin(); }
86 std::reverse_iterator<const_iterator> rbegin()
const {
return vec.rbegin(); }
87 std::reverse_iterator<iterator> rend() {
return vec.rend(); }
88 std::reverse_iterator<const_iterator> rend()
const {
return vec.rend(); }
89 size_t size()
const override {
return vec.size(); }
90 void resize(
size_t sz) { vec.resize(sz); }
91 bool empty()
const override {
return vec.empty(); }
92 const T *
const &front()
const {
return vec.front(); }
93 const T *&front() {
return vec.front(); }
94 void clear() { vec.clear(); }
95 iterator erase(iterator i) {
return vec.erase(i); }
96 iterator erase(iterator s, iterator e) {
return vec.erase(s, e); }
97 template <
typename ForwardIter>
98 iterator insert(iterator i, ForwardIter b, ForwardIter e) {
101 int index = i - vec.begin();
103 return vec.begin() + index;
106 template <
typename Container>
107 iterator append(
const Container &toAppend) {
108 return insert(end(), toAppend.begin(), toAppend.end());
110 template <
typename Container>
111 iterator prepend(
const Container &toAppend) {
112 return insert(begin(), toAppend.begin(), toAppend.end());
122 if (item ==
nullptr)
return;
124 append(*itemAsVector);
127 BUG_CHECK(item->
is<T>(),
"Unexpected vector element: %1%", item);
128 push_back(item->
to<T>());
131 iterator insert(iterator i,
const T *v) {
134 int index = i - vec.begin();
136 return vec.begin() + index;
138 iterator insert(iterator i,
size_t n,
const T *v) {
141 int index = i - vec.begin();
143 return vec.begin() + index;
146 const T *
const &operator[](
size_t idx)
const {
return vec[idx]; }
147 const T *&operator[](
size_t idx) {
return vec[idx]; }
148 const T *
const &at(
size_t idx)
const {
return vec.at(idx); }
149 const T *&at(
size_t idx) {
return vec.at(idx); }
150 template <
class... Args>
151 void emplace_back(Args &&...args) {
152 vec.emplace_back(
new T(std::forward<Args>(args)...));
154 void push_back(T *a) { vec.push_back(a); }
155 void push_back(
const T *a) { vec.push_back(a); }
156 void pop_back() { vec.pop_back(); }
157 const T *
const &back()
const {
return vec.back(); }
158 const T *&back() {
return vec.back(); }
160 void push_back(U &a) {
163 void check_null()
const {
164 for (
auto e : vec) CHECK_NULL(e);
167 IRNODE_SUBCLASS(Vector)
168 IRNODE_DECLARE_APPLY_OVERLOAD(Vector)
169 bool operator==(
const Node &a)
const override {
return a == *
this; }
170 bool operator==(
const Vector &a)
const override {
return vec == a.vec; }
185 bool equiv(
const Node &a_)
const override {
186 if (
static_cast<const Node *
>(
this) == &a_)
return true;
187 if (this->
typeId() != a_.typeId())
return false;
188 auto &a =
static_cast<const Vector<T> &
>(a_);
189 if (size() != a.size())
return false;
191 for (
auto *el : *this)
192 if (!el->equiv(**it++)) return false;
195 cstring node_type_name()
const override {
return "Vector<" + T::static_type_name() +
">"; }
196 static cstring static_type_name() {
return "Vector<" + T::static_type_name() +
">"; }
197 void visit_children(
Visitor &v)
override;
198 void visit_children(
Visitor &v)
const override;
199 virtual void parallel_visit_children(
Visitor &v);
200 virtual void parallel_visit_children(
Visitor &v)
const;
203 template <
typename S>
206 [](
const T *d) {
return d !=
nullptr; });
209 DECLARE_TYPEINFO_WITH_DISCRIMINATOR(Vector<T>, NodeDiscriminator::VectorT, T, VectorBase);