12 using std::vector<T>::vector;
32 const T&
get(
size_t index)
const;
34 int find(
const T& what,
int from = 0)
const;
38 bool has(
const T& what)
const;
50 template <
typename Func>
51 void sort(Func comparator);
57 template<
typename Func>
60 template <
typename Func>
61 auto map(Func func)
const;
63 template <
typename Func>
66 template <
typename U,
typename Func>
67 U
reduce(Func func, U initial_value)
const;
69 bool all(std::function<
bool(
const T&)> predicate)
const;
71 bool any(std::function<
bool(
const T&)> predicate)
const;
90 this->insert(this->begin(), value);
95 this->push_back(value);
100 this->insert(this->end(), other.begin(), other.end());
103 template <
typename T>
105 if (!this->empty()) {
106 this->erase(this->begin());
110 template <
typename T>
112 if (position < this->size()) {
113 std::vector<T>::erase(this->begin() + position);
117 template <
typename T>
122 template <
typename T>
127 template <
typename T>
129 return (*
this)[index];
132 template <
typename T>
134 return (*
this)[index];
137 template <
typename T>
139 for (
size_t i = from; i < this->size(); ++i) {
140 if ((*
this)[i] == what) {
141 return static_cast<int>(i);
148 template <
typename T>
150 for (
int i = this->size() - 1; i >= 0; --i) {
151 if ((*
this)[i] == what) {
159 template <
typename T>
161 return find(what) != -1;
164 template <
typename T>
167 for (
const auto& item : *
this) {
176 template <
typename T>
179 result.assign(this->begin(), this->end());
183 template <
typename T>
190 if (end_pos >
static_cast<int>(this->size())) {
191 end_pos = this->size();
194 if (begin_pos < end_pos) {
195 result.assign(this->begin() + begin_pos, this->begin() + end_pos);
201 template <
typename T>
203 std::reverse(this->begin(), this->end());
206 template <
typename T>
208 std::sort(this->begin(), this->end());
211 template <
typename T>
212 template <
typename Func>
214 std::sort(this->begin(), this->end(), comparator);
217 template <
typename T>
220 throw std::runtime_error(
"Cannot find min of empty array");
223 return *std::min_element(this->begin(), this->end());
226 template <
typename T>
229 throw std::runtime_error(
"Cannot find max of empty array");
232 return *std::max_element(this->begin(), this->end());
235 template <
typename T>
236 template <
typename Func>
239 std::copy_if(this->begin(), this->end(), std::back_inserter(result), predicate);
243 template <
typename T>
244 template <
typename Func>
246 using ReturnType = decltype(func(std::declval<T>()));
248 result.reserve(this->size());
249 std::transform(this->begin(), this->end(), std::back_inserter(result), func);
253 template <
typename T>
254 template <
typename Func>
256 std::for_each(this->begin(), this->end(), func);
259 template <
typename T>
260 template <
typename U,
typename Func>
262 U result = initial_value;
263 for (
const auto& item : *
this) {
264 result = func(result, item);
269 template <
typename T>
271 return std::all_of(this->begin(), this->end(), predicate);
274 template <
typename T>
276 return std::any_of(this->begin(), this->end(), predicate);
279 template <
typename T>
282 throw std::out_of_range(
"Array is empty");
285 return this->front();
288 template <
typename T>
291 throw std::out_of_range(
"Array is empty");
294 return this->front();
297 template <
typename T>
300 throw std::out_of_range(
"Array is empty");
306 template <
typename T>
309 throw std::out_of_range(
"Array is empty");
TypedArray< T > duplicate(bool deep=false) const
Definition: vector.h:177
void erase(size_t position)
Definition: vector.h:111
void remove_at(size_t position)
Definition: vector.h:123
void sort()
Definition: vector.h:207
const T & last() const
Definition: vector.h:307
bool has(const T &what) const
Definition: vector.h:160
void for_each(Func func)
Definition: vector.h:255
bool is_empty() const
Definition: vector.h:84
void remove(size_t position)
Definition: vector.h:118
int rfind(const T &what) const
Definition: vector.h:149
const T & first() const
Definition: vector.h:289
void reverse()
Definition: vector.h:202
T & first()
Definition: vector.h:280
int find(const T &what, int from=0) const
Definition: vector.h:138
int count(const T &what) const
Definition: vector.h:165
void append(const T &value)
Definition: vector.h:94
bool any(std::function< bool(const T &)> predicate) const
Definition: vector.h:275
T & last()
Definition: vector.h:298
T min() const
Definition: vector.h:218
void sort(Func comparator)
Definition: vector.h:213
TypedArray< T > filter(Func predicate) const
Definition: vector.h:237
bool all(std::function< bool(const T &)> predicate) const
Definition: vector.h:270
void pop_front()
Definition: vector.h:104
auto map(Func func) const
Definition: vector.h:245
void push_front(const T &value)
Definition: vector.h:89
TypedArray< T > slice(int begin_pos, int end_pos=INT32_MAX) const
Definition: vector.h:184
void append_array(const TypedArray< T > &other)
Definition: vector.h:99
const T & get(size_t index) const
Definition: vector.h:133
T max() const
Definition: vector.h:227
U reduce(Func func, U initial_value) const
Definition: vector.h:261
T & get(size_t index)
Definition: vector.h:128