63 typedef const T *value_type;
70 explicit Vector(
const T *a) { vec.emplace_back(std::move(a)); }
72 Vector(
const std::initializer_list<const T *> &a) : vec(a) {}
74 typedef typename safe_vector<const T *>::iterator iterator;
75 typedef typename safe_vector<const T *>::const_iterator const_iterator;
76 iterator begin() {
return vec.begin(); }
77 const_iterator begin()
const {
return vec.begin(); }
78 VectorBase::iterator VectorBase_begin()
const override {
80 return reinterpret_cast<VectorBase::iterator
>(&vec[0]);
82 iterator end() {
return vec.end(); }
83 const_iterator end()
const {
return vec.end(); }
84 VectorBase::iterator VectorBase_end()
const override {
86 return reinterpret_cast<VectorBase::iterator
>(&vec[0] + vec.size());
88 std::reverse_iterator<iterator> rbegin() {
return vec.rbegin(); }
89 std::reverse_iterator<const_iterator> rbegin()
const {
return vec.rbegin(); }
90 std::reverse_iterator<iterator> rend() {
return vec.rend(); }
91 std::reverse_iterator<const_iterator> rend()
const {
return vec.rend(); }
92 size_t size()
const override {
return vec.size(); }
93 void resize(
size_t sz) { vec.resize(sz); }
94 bool empty()
const override {
return vec.empty(); }
95 const T *
const &front()
const {
return vec.front(); }
96 const T *&front() {
return vec.front(); }
97 void clear() { vec.clear(); }
98 iterator erase(iterator i) {
return vec.erase(i); }
99 iterator erase(iterator s, iterator e) {
return vec.erase(s, e); }
100 template <
typename ForwardIter>
101 iterator insert(iterator i, ForwardIter b, ForwardIter e) {
104 int index = i - vec.begin();
106 return vec.begin() + index;
109 template <
typename Container>
110 iterator append(
const Container &toAppend) {
111 return insert(end(), toAppend.begin(), toAppend.end());
113 template <
typename Container>
114 iterator prepend(
const Container &toAppend) {
115 return insert(begin(), toAppend.begin(), toAppend.end());
125 if (item ==
nullptr)
return;
127 append(*itemAsVector);
130 BUG_CHECK(item->
is<T>(),
"Unexpected vector element: %1%", item);
131 push_back(item->
to<T>());
134 iterator insert(iterator i,
const T *v) {
137 int index = i - vec.begin();
139 return vec.begin() + index;
141 iterator insert(iterator i,
size_t n,
const T *v) {
144 int index = i - vec.begin();
146 return vec.begin() + index;
149 const T *
const &operator[](
size_t idx)
const {
return vec[idx]; }
150 const T *&operator[](
size_t idx) {
return vec[idx]; }
151 const T *
const &at(
size_t idx)
const {
return vec.at(idx); }
152 const T *&at(
size_t idx) {
return vec.at(idx); }
153 template <
class... Args>
154 void emplace_back(Args &&...args) {
155 vec.emplace_back(
new T(std::forward<Args>(args)...));
157 void push_back(T *a) { vec.push_back(a); }
158 void push_back(
const T *a) { vec.push_back(a); }
159 void pop_back() { vec.pop_back(); }
160 const T *
const &back()
const {
return vec.back(); }
161 const T *&back() {
return vec.back(); }
163 void push_back(U &a) {
166 void check_null()
const {
167 for (
auto e : vec) CHECK_NULL(e);
170 IRNODE_SUBCLASS(Vector)
171 IRNODE_DECLARE_APPLY_OVERLOAD(Vector)
172 bool operator==(
const Node &a)
const override {
return a == *
this; }
173 bool operator==(
const Vector &a)
const override {
return vec == a.vec; }
188 bool equiv(
const Node &a_)
const override {
189 if (
static_cast<const Node *
>(
this) == &a_)
return true;
190 if (this->
typeId() != a_.typeId())
return false;
191 auto &a =
static_cast<const Vector<T> &
>(a_);
192 if (size() != a.size())
return false;
194 for (
auto *el : *
this)
195 if (!el->equiv(**it++))
return false;
198 cstring node_type_name()
const override {
return "Vector<" + T::static_type_name() +
">"; }
199 static cstring static_type_name() {
return "Vector<" + T::static_type_name() +
">"; }
200 void visit_children(Visitor &v)
override;
201 void visit_children(Visitor &v)
const override;
202 virtual void parallel_visit_children(Visitor &v);
203 virtual void parallel_visit_children(Visitor &v)
const;
204 void toJSON(JSONGenerator &json)
const override;
205 Util::Enumerator<const T *> *getEnumerator()
const {
return Util::enumerate(vec); }
206 template <
typename S>
207 Util::Enumerator<const S *> *only()
const {
209 [](
const T *d) {
return d !=
nullptr; });
212 void dbprint(std::ostream &out)
const override {
213 out <<
"{" << IndentCtl::indent;
214 for (
auto p : *
this) {
217 out << IndentCtl::unindent <<
" }";
220 DECLARE_TYPEINFO_WITH_DISCRIMINATOR(Vector<T>, NodeDiscriminator::VectorT, T, VectorBase);