diff --git a/libs/main/containers/pivector.h b/libs/main/containers/pivector.h index 9e5b04a1..4108ec6d 100644 --- a/libs/main/containers/pivector.h +++ b/libs/main/containers/pivector.h @@ -1218,7 +1218,7 @@ public: //! v.remove(1, 2); //! piCout << v; // 1, 5 //! \endcode - //! \~\sa \a resize(), \a insert() + //! \~\sa \a resize(), \a insert(), \a removeOne(), \a removeAll(), \a removeWhere() inline PIVector & remove(size_t index, size_t count = 1) { if (count == 0) return *this; if (index + count >= piv_size) { @@ -1291,17 +1291,36 @@ public: return ret.reverse(); } - inline PIVector & enlarge(llong piv_size, const T & e = T()) { - llong ns = size_s() + piv_size; + //! \~\brief + //! \~english Increases or decreases the size of the array by `add_size` elements. + //! \~russian Увеличивает или уменьшает размер массива на `add_size` элементов. + //! \~\details + //! \~english If `add_size > 0` then elements are added to the end of the array. + //! If `add_size < 0` then elements are removed from the end of the array. + //! If `add_size < 0` and there are fewer elements in the array than specified, then the array becomes empty. + //! \~russian Если `add_size > 0` то в конец массива добавляются элементы. + //! Если `add_size < 0` то с конца массива удаляются элементы. + //! Если `add_size < 0` и в массиве меньше элементов чем указано, то массив становится пустым. + //! \~\sa \a resize() + inline PIVector & enlarge(llong add_size, const T & e = T()) { + llong ns = size_s() + add_size; if (ns <= 0) clear(); else resize(size_t(ns), e); return *this; } -/*! \brief Remove no more than one element equal "v" and return reference to vector -* \details Example: \snippet picontainers.cpp PIVector::removeOne -* \sa \a remove(), \a removeAll() -*/ + //! \brief + //! \~english Remove no more than one element equal "v" and return reference to vector + //! \~russian + //! \details + //! \~english + //! \~russian + //! \~\code + //! PIVector v{3, 2, 5, 2, 7}; + //! v.removeOne(2); + //! piCout << v; // 3, 5, 2, 7 + //! \endcode + //! \~\sa \a remove(), \a removeAll(), \a removeWhere() inline PIVector & removeOne(const T & e) { for (size_t i = 0; i < piv_size; ++i) { if (piv_data[i] == e) { @@ -1311,6 +1330,19 @@ public: } return *this; } + + //! \brief + //! \~english Remove no more than one element equal "v" and return reference to vector + //! \~russian + //! \details + //! \~english + //! \~russian + //! \~\code + //! PIVector v{3, 2, 5, 2, 7}; + //! v.removeAll(2); + //! piCout << v; // 3, 5, 7 + //! \endcode + //! \~\sa \a remove(), \a removeOne(), \a removeWhere() inline PIVector & removeAll(const T & e) { for (ssize_t i = 0; i < size_s(); ++i) { if (piv_data[i] == e) { @@ -1320,6 +1352,7 @@ public: } return *this; } + inline PIVector & removeWhere(std::function test) { for (ssize_t i = 0; i < size_s(); ++i) { if (test(piv_data[i])) {