PIVector doc, forEach refactory
This commit is contained in:
@@ -515,7 +515,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 8, 9};
|
||||
//! piCout << v.any([](int e){return e % 2 == 0;}); // true
|
||||
//! piCout << v.any([](int e){return e == 3;}); // false
|
||||
//! piCout << v.any([](int e){return e == 3;}); // false
|
||||
//! \endcode
|
||||
//! \~\sa \a every(), \a contains(), \a etries(), \a forEach()
|
||||
inline bool any(std::function<bool(const T & e)> test) const {
|
||||
@@ -541,7 +541,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 8, 9};
|
||||
//! piCout << v.every([](int e){return e % 2 == 0;}); // false
|
||||
//! piCout << v.every([](int e){return e > 0;}); // true
|
||||
//! piCout << v.every([](int e){return e > 0;}); // true
|
||||
//! \endcode
|
||||
//! \~\sa \a any(), \a contains(), \a entries(), \a forEach()
|
||||
inline bool every(std::function<bool(const T & e)> test) const {
|
||||
@@ -565,7 +565,7 @@ public:
|
||||
//! PIVector<int> v{1, 2, 8, 9};
|
||||
//! piCout << v[2]; // 8
|
||||
//! v[2] = 5;
|
||||
//! piCout << v; // 1, 2, 5, 9
|
||||
//! piCout << v; // {1, 2, 5, 9}
|
||||
//! \endcode
|
||||
//! \~\sa \a at()
|
||||
inline T & operator [](size_t index) {return piv_data[index];}
|
||||
@@ -650,10 +650,10 @@ public:
|
||||
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3, 4};
|
||||
//! piCout << v.contains(3); // true
|
||||
//! piCout << v.contains(5); // false
|
||||
//! piCout << v.contains(3, 3); // false
|
||||
//! piCout << v.contains(3, -2); // true
|
||||
//! piCout << v.contains(3); // true
|
||||
//! piCout << v.contains(5); // false
|
||||
//! piCout << v.contains(3, 3); // false
|
||||
//! piCout << v.contains(3, -2); // true
|
||||
//! piCout << v.contains(3, -99); // true
|
||||
//! \endcode
|
||||
//! \~\return
|
||||
@@ -694,8 +694,8 @@ public:
|
||||
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{2, 2, 4, 2, 6};
|
||||
//! piCout << v.entries(2); // 3
|
||||
//! piCout << v.entries(2, 2); // 1
|
||||
//! piCout << v.entries(2); // 3
|
||||
//! piCout << v.entries(2, 2); // 1
|
||||
//! piCout << v.entries(2, -4); // 2
|
||||
//! \endcode
|
||||
//! \~\sa \a every(), \a any(), \a contains(), \a forEach(), \a indexOf()
|
||||
@@ -854,12 +854,12 @@ public:
|
||||
//! и означает, что просматривается весь массив.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{2, 5, 9, 2};
|
||||
//! piCout << v.lastIndexOf(2); // 3
|
||||
//! piCout << v.lastIndexOf(7); // -1
|
||||
//! piCout << v.lastIndexOf(2, 2); // 0
|
||||
//! piCout << v.lastIndexOf(2, -3); // 0
|
||||
//! piCout << v.lastIndexOf(2); // 3
|
||||
//! piCout << v.lastIndexOf(7); // -1
|
||||
//! piCout << v.lastIndexOf(2, 2); // 0
|
||||
//! piCout << v.lastIndexOf(2, -3); // 0
|
||||
//! piCout << v.lastIndexOf(2, -300); // -1
|
||||
//! piCout << v.lastIndexOf(2, 300); // 3
|
||||
//! piCout << v.lastIndexOf(2, 300); // 3
|
||||
//! \endcode
|
||||
//! \~\sa \a indexOf(), \a indexWhere(), \a lastIndexWhere(), \a contains()
|
||||
inline ssize_t lastIndexOf(const T & e, ssize_t start = -1) const {
|
||||
@@ -918,7 +918,7 @@ public:
|
||||
//! PIVector<int> v{2, 5, 9, 2};
|
||||
//! int a[2] = {12, 13};
|
||||
//! memcpy(vec.data(1), carr, 2 * sizeof(int));
|
||||
//! piCout << v; // 2, 12, 13, 2
|
||||
//! piCout << v; // {2, 12, 13, 2}
|
||||
//! \endcode
|
||||
inline T * data(size_t index = 0) {return &(piv_data[index]);}
|
||||
|
||||
@@ -995,7 +995,7 @@ public:
|
||||
//! \code
|
||||
//! PIVector<int> v{1, 3, 5};
|
||||
//! v.fill(7);
|
||||
//! piCout << v; // 7, 7, 7
|
||||
//! piCout << v; // {7, 7, 7}
|
||||
//! \endcode
|
||||
//! \~\sa \a resize()
|
||||
inline PIVector<T> & fill(const T & f = T()) {
|
||||
@@ -1014,7 +1014,7 @@ public:
|
||||
//! \code
|
||||
//! PIVector<int> v{1, 3, 5};
|
||||
//! v.fill([](size_t i){return i*2;});
|
||||
//! piCout << v; // 0, 2, 4
|
||||
//! piCout << v; // {0, 2, 4}
|
||||
//! \endcode
|
||||
//! \~\sa \a resize()
|
||||
inline PIVector<T> & fill(std::function<T(size_t i)> f) {
|
||||
@@ -1160,7 +1160,7 @@ public:
|
||||
//! \code
|
||||
//! PIVector<int> v{1, 3, 5};
|
||||
//! v.insert(2, 7);
|
||||
//! piCout << v; // 1, 3, 7, 5
|
||||
//! piCout << v; // {1, 3, 7, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||
inline PIVector<T> & insert(size_t index, const T & e = T()) {
|
||||
@@ -1223,7 +1223,7 @@ public:
|
||||
//! \code
|
||||
//! PIVector<int> v{1, 3, 7, 5};
|
||||
//! v.remove(1, 2);
|
||||
//! piCout << v; // 1, 5
|
||||
//! piCout << v; // {1, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a resize(), \a insert(), \a removeOne(), \a removeAll(), \a removeWhere()
|
||||
inline PIVector<T> & remove(size_t index, size_t count = 1) {
|
||||
@@ -1266,7 +1266,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
|
||||
//! v.sort();
|
||||
//! piCout << v; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
//! piCout << v; // {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
//! \endcode
|
||||
//! \~\sa \a sort(std::function<bool(const T &a, const T &b)> comp)
|
||||
inline PIVector<T> & sort() {
|
||||
@@ -1301,7 +1301,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
|
||||
//! v.sort([](const int & a, const int & b){return a > b;});
|
||||
//! piCout << v; // 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||
//! piCout << v; // {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
|
||||
//! \endcode
|
||||
//! \~\sa \a sort()
|
||||
inline PIVector<T> & sort(std::function<bool(const T &a, const T &b)> comp) {
|
||||
@@ -1324,7 +1324,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 3, 7, 5};
|
||||
//! v.reverse();
|
||||
//! piCout << v; // 5, 7, 3, 1
|
||||
//! piCout << v; // {5, 7, 3, 1}
|
||||
//! \endcode
|
||||
//! \~\sa \a reversed()
|
||||
inline PIVector<T> & reverse() {
|
||||
@@ -1374,7 +1374,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{3, 2, 5, 2, 7};
|
||||
//! v.removeOne(2);
|
||||
//! piCout << v; // 3, 5, 2, 7
|
||||
//! piCout << v; // {3, 5, 2, 7}
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeAll(), \a removeWhere()
|
||||
inline PIVector<T> & removeOne(const T & e) {
|
||||
@@ -1394,7 +1394,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{3, 2, 5, 2, 7};
|
||||
//! v.removeAll(2);
|
||||
//! piCout << v; // 3, 5, 7
|
||||
//! piCout << v; // {3, 5, 7}
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIVector<T> & removeAll(const T & e) {
|
||||
@@ -1416,7 +1416,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{3, 2, 5, 2, 7};
|
||||
//! v.removeWhere([](const int & i){return i > 2;});
|
||||
//! piCout << v; // 2, 2
|
||||
//! piCout << v; // {2, 2}
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIVector<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||
@@ -1449,7 +1449,7 @@ public:
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.push_back(4);
|
||||
//! v.push_back(5);
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a push_front(), \a append(), \a prepend(), \a insert()
|
||||
inline PIVector<T> & push_back(const T & e) {
|
||||
@@ -1531,7 +1531,7 @@ public:
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.append(4);
|
||||
//! v.append(5);
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a prepend(), \a push_front(), \a push_back(), \a insert()
|
||||
inline PIVector<T> & append(const T & e) {return push_back(e);}
|
||||
@@ -1567,7 +1567,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.append(PIVector<int>{4, 5});
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a append()
|
||||
inline PIVector<T> & append(const PIVector<T> & v) {return push_back(v);}
|
||||
@@ -1579,7 +1579,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v << 4 << 5;
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a append()
|
||||
inline PIVector<T> & operator <<(const T & e) {return push_back(e);}
|
||||
@@ -1591,7 +1591,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v << 4 << 5;
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a append()
|
||||
inline PIVector<T> & operator <<(T && e) {return push_back(std::move(e));}
|
||||
@@ -1603,7 +1603,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v << PIVector<int>{4, 5};
|
||||
//! piCout << v; // 1, 2, 3, 4, 5
|
||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||
//! \endcode
|
||||
//! \~\sa \a append()
|
||||
inline PIVector<T> & operator <<(const PIVector<T> & v) {return push_back(v);}
|
||||
@@ -1622,7 +1622,7 @@ public:
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.push_front(4);
|
||||
//! v.push_front(5);
|
||||
//! piCout << v; // 5, 4, 1, 2, 3
|
||||
//! piCout << v; // {5, 4, 1, 2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a push_back(), \a append(), \a prepend(), \a insert()
|
||||
inline PIVector<T> & push_front(const T & e) {
|
||||
@@ -1651,7 +1651,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.push_front(PIVector<int>{4, 5});
|
||||
//! piCout << v; // 4, 5, 1, 2, 3
|
||||
//! piCout << v; // {4, 5, 1, 2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a push_front()
|
||||
inline PIVector<T> & push_front(const PIVector<T> & v) {
|
||||
@@ -1673,7 +1673,7 @@ public:
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.prepend(4);
|
||||
//! v.prepend(5);
|
||||
//! piCout << v; // 5, 4, 1, 2, 3
|
||||
//! piCout << v; // {5, 4, 1, 2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a append(), \a push_back(), \a push_front(), \a insert()
|
||||
inline PIVector<T> & prepend(const T & e) {return push_front(e);}
|
||||
@@ -1696,38 +1696,100 @@ public:
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.prepend(PIVector<int>{4, 5});
|
||||
//! piCout << v; // 4, 5, 1, 2, 3
|
||||
//! piCout << v; // {4, 5, 1, 2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a prepend()
|
||||
inline PIVector<T> & prepend(const PIVector<T> & v) {return push_front(v);}
|
||||
|
||||
//! \brief
|
||||
//! \~english Remove one element from the end of the array.
|
||||
//! \~russian Удаляет один элемент с конца массива.
|
||||
//! \~\details
|
||||
//! \~english Deleting an element from the end is very fast
|
||||
//! and does not depend on the size of the array.
|
||||
//! \~russian Удаление элемента с конца выполняется очень быстро
|
||||
//! и не зависит от размера массива.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.pop_back();
|
||||
//! piCout << v; // {1, 2}
|
||||
//! \endcode
|
||||
//! \~\sa \a pop_front(), \a take_back(), \a take_front()
|
||||
inline PIVector<T> & pop_back() {
|
||||
if (piv_size == 0) return *this;
|
||||
resize(piv_size - 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Remove one element from the begining of the array.
|
||||
//! \~russian Удаляет один элемент с начала массива.
|
||||
//! \~\details
|
||||
//! \~english Removing an element from the beginning takes longer than from the end.
|
||||
//! This time is directly proportional to the size of the array.
|
||||
//! All iterators and references are invalidated.
|
||||
//! \~russian Удаление элемента с начала выполняется дольше чем с конца.
|
||||
//! Это время прямопропорционально размеру массива.
|
||||
//! При удалении элемента все итераторы и указатели становятся нерабочими.
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! v.pop_front();
|
||||
//! piCout << v; // {2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a pop_back(), \a take_back(), \a take_front()
|
||||
inline PIVector<T> & pop_front() {
|
||||
if (piv_size == 0) return *this;
|
||||
remove(0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Remove one element from the end of the array and return it.
|
||||
//! \~russian Удаляет один элемент с начала массива и возвращает его.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! piCout << v.take_back(); // 3
|
||||
//! piCout << v; // {1, 2}
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_back() {
|
||||
T e(back());
|
||||
pop_back();
|
||||
return e;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Remove one element from the begining of the array and return it.
|
||||
//! \~russian Удаляет один элемент с конца массива и возвращает его.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIVector<int> v{1, 2, 3};
|
||||
//! piCout << v.take_front(); // 1
|
||||
//! piCout << v; // {2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
inline T take_front() {
|
||||
T e(front());
|
||||
pop_front();
|
||||
return e;
|
||||
}
|
||||
|
||||
//! \brief
|
||||
//! \~english Returns an array converted to another type.
|
||||
//! \~russian Возвращает конвертированный в другой тип массив.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIVector<double> v{1.1, 2.5, 3.8};
|
||||
//! PIVector<int> v2 = v.toType<int>();
|
||||
//! piCout << v2; // {1, 2, 3}
|
||||
//! \endcode
|
||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
||||
template <typename ST>
|
||||
inline PIVector<ST> toType() const {
|
||||
PIVector<ST> ret(piv_size);
|
||||
PIVector<ST> ret; ret.reserve(piv_size);
|
||||
for (size_t i = 0; i < piv_size; ++i) {
|
||||
ret[i] = ST(piv_data[i]);
|
||||
ret << ST(piv_data[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1740,24 +1802,15 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline const PIVector<T> & forEach(std::function<void(const T & e)> f) const {
|
||||
inline void forEach(std::function<void(const T & e)> f) const {
|
||||
for (size_t i = 0; i < piv_size; ++i) {
|
||||
f(piv_data[i]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PIVector<T> copyForEach(std::function<T(const T & e)> f) const {
|
||||
PIVector<T> ret; ret.reserve(piv_size);
|
||||
inline PIVector<T> & forEach(std::function<void(T & e)> f) {
|
||||
for (size_t i = 0; i < piv_size; ++i) {
|
||||
ret << f(piv_data[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline PIVector<T> & forEachInplace(std::function<T(const T & e)> f) {
|
||||
for (size_t i = 0; i < piv_size; ++i) {
|
||||
piv_data[i] = f(piv_data[i]);
|
||||
f(piv_data[i]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1771,9 +1824,6 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename ST>
|
||||
inline PIVector<ST> toType(std::function<ST(const T & e)> f) const {return map(f);}
|
||||
|
||||
template <typename ST>
|
||||
inline ST reduce(std::function<ST(const T & e, const ST & acc)> f, const ST & initial = ST()) const {
|
||||
ST ret(initial);
|
||||
|
||||
Reference in New Issue
Block a user