PIDeque doc, fixes in PIVector and PIString
This commit is contained in:
@@ -105,36 +105,84 @@ class PIDeque {
|
|||||||
public:
|
public:
|
||||||
typedef bool (*CompareFunc)(const T & , const T & );
|
typedef bool (*CompareFunc)(const T & , const T & );
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Constructs an empty array.
|
||||||
|
//! \~russian Создает пустой массив.
|
||||||
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Copy constructor.
|
||||||
|
//! \~russian Копирующий конструктор.
|
||||||
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
alloc_forward(other.pid_size);
|
alloc_forward(other.pid_size);
|
||||||
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
|
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Contructs array from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Создает массив из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque <int> v{1,2,3};
|
||||||
|
//! piCout << v; // {1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
inline PIDeque(std::initializer_list<T> init_list): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
inline PIDeque(std::initializer_list<T> init_list): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
alloc_forward(init_list.size());
|
alloc_forward(init_list.size());
|
||||||
newT(pid_data, init_list.begin(), init_list.size());
|
newT(pid_data, init_list.begin(), init_list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Contructs array from raw `data`.
|
||||||
|
//! This constructor reserve `size` and copy from `data` pointer.
|
||||||
|
//! \~russian Создает массив из указателя на данные `data` и размер `size`.
|
||||||
|
//! То есть выделяет память для `size` элементов и копирует данные из указателя `data`.
|
||||||
inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
alloc_forward(size);
|
alloc_forward(size);
|
||||||
newT(pid_data + pid_start, data, pid_size);
|
newT(pid_data + pid_start, data, pid_size);
|
||||||
}
|
}
|
||||||
inline PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Contructs array with size `size` filled elements `e`.
|
||||||
|
//! \~russian Создает массив из `size` элементов заполненных `e`.
|
||||||
|
inline PIDeque(size_t pid_size, const T & e = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
resize(pid_size, f);
|
resize(pid_size, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Contructs array with size `size` and elements created by function `f(size_t i)`.
|
||||||
|
//! \~russian Создает массив из `size` элементов созданных функцией `f(size_t i)`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Can use
|
||||||
|
//! [Lambda expressions](https://en.cppreference.com/w/cpp/language/lambda)
|
||||||
|
//! as constructor argument.
|
||||||
|
//! \~russian Позволяет передавать
|
||||||
|
//! [Лямбда-выражения](https://ru.cppreference.com/w/cpp/language/lambda)
|
||||||
|
//! для создания элементов в конструкторе.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque <int> v(5, [](size_t i){return i*2;});
|
||||||
|
//! piCout << v; // {0, 2, 4, 6, 8}
|
||||||
|
//! \endcode
|
||||||
inline PIDeque(size_t piv_size, std::function<T(size_t i)> f): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
inline PIDeque(size_t piv_size, std::function<T(size_t i)> f): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
resize(piv_size, f);
|
resize(piv_size, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Move constructor.
|
||||||
|
//! \~russian Перемещающий конструктор.
|
||||||
inline PIDeque(PIDeque<T> && other): pid_data(other.pid_data), pid_size(other.pid_size), pid_rsize(other.pid_rsize), pid_start(other.pid_start) {
|
inline PIDeque(PIDeque<T> && other): pid_data(other.pid_data), pid_size(other.pid_size), pid_rsize(other.pid_rsize), pid_start(other.pid_start) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
other._reset();
|
other._reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline virtual ~PIDeque() {
|
inline virtual ~PIDeque() {
|
||||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||||
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize))
|
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize))
|
||||||
@@ -143,6 +191,9 @@ public:
|
|||||||
_reset();
|
_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Assign operator.
|
||||||
|
//! \~russian Оператор присваивания.
|
||||||
inline PIDeque<T> & operator =(const PIDeque<T> & other) {
|
inline PIDeque<T> & operator =(const PIDeque<T> & other) {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
deleteT(pid_data + pid_start, pid_size);
|
deleteT(pid_data + pid_start, pid_size);
|
||||||
@@ -151,18 +202,14 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Assign move operator.
|
||||||
|
//! \~russian Оператор перемещающего присваивания.
|
||||||
inline PIDeque<T> & operator =(PIDeque<T> && other) {
|
inline PIDeque<T> & operator =(PIDeque<T> && other) {
|
||||||
swap(other);
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef T value_type;
|
|
||||||
|
|
||||||
enum ReshapeOrder {
|
|
||||||
byRow,
|
|
||||||
byColumn
|
|
||||||
};
|
|
||||||
|
|
||||||
class iterator {
|
class iterator {
|
||||||
friend class PIDeque<T>;
|
friend class PIDeque<T>;
|
||||||
private:
|
private:
|
||||||
@@ -178,34 +225,94 @@ public:
|
|||||||
|
|
||||||
inline iterator(): parent(0), pos(0) {}
|
inline iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline T & operator *() {return (*parent)[pos];}
|
inline T & operator *() {
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
inline T & operator ->() {return (*parent)[pos];}
|
}
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline T & operator ->() {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline iterator & operator ++() {++pos; return *this;}
|
inline iterator & operator ++() {
|
||||||
inline iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
++pos;
|
||||||
inline iterator & operator --() {--pos; return *this;}
|
return *this;
|
||||||
inline iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
}
|
||||||
|
inline iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline iterator & operator --() {
|
||||||
|
--pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline iterator & operator +=(const iterator & it) {pos += it.pos; return *this;}
|
inline iterator & operator +=(const iterator & it) {
|
||||||
inline iterator & operator +=(size_t p) {pos += p; return *this;}
|
pos += it.pos;
|
||||||
inline iterator & operator -=(const iterator & it) {pos -= it.pos; return *this;}
|
return *this;
|
||||||
inline iterator & operator -=(size_t p) {pos -= p; return *this;}
|
}
|
||||||
|
inline iterator & operator +=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator -=(const iterator & it) {
|
||||||
|
pos -= it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator -=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline iterator operator -(const iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline iterator operator -(const iterator & it, size_t p) {
|
||||||
friend inline iterator operator -(size_t p, const iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const iterator & it1, const iterator & it2) {return it1.pos - it2.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline iterator operator -(size_t p, const iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos - it2.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline iterator operator +(const iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline iterator operator +(const iterator & it, size_t p) {
|
||||||
friend inline iterator operator +(size_t p, const iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline iterator operator +(size_t p, const iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const iterator & it) const {
|
||||||
inline bool operator !=(const iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const iterator & it1, const iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const iterator & it1, const iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const iterator & it) const {
|
||||||
friend inline bool operator >(const iterator & it1, const iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const iterator & it1, const iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
@@ -223,32 +330,88 @@ public:
|
|||||||
|
|
||||||
inline const_iterator(): parent(0), pos(0) {}
|
inline const_iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline const_iterator & operator ++() {++pos; return *this;}
|
inline const_iterator & operator ++() {
|
||||||
inline const_iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
++pos;
|
||||||
inline const_iterator & operator --() {--pos; return *this;}
|
return *this;
|
||||||
inline const_iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
}
|
||||||
|
inline const_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator --() {
|
||||||
|
--pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline const_iterator & operator +=(const const_iterator & it) {pos += it.pos; return *this;}
|
inline const_iterator & operator +=(const const_iterator & it) {
|
||||||
inline const_iterator & operator +=(size_t p) {pos += p; return *this;}
|
pos += it.pos;
|
||||||
inline const_iterator & operator -=(const const_iterator & it) {pos -= it.pos; return *this;}
|
return *this;
|
||||||
inline const_iterator & operator -=(size_t p) {pos -= p; return *this;}
|
}
|
||||||
|
inline const_iterator & operator +=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator -=(const const_iterator & it) {
|
||||||
|
pos -= it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator -=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_iterator operator -(const const_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline const_iterator operator -(const const_iterator & it, size_t p) {
|
||||||
friend inline const_iterator operator -(size_t p, const const_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const const_iterator & it1, const const_iterator & it2) {return it1.pos - it2.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_iterator operator -(size_t p, const const_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos - it2.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_iterator operator +(const const_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline const_iterator operator +(const const_iterator & it, size_t p) {
|
||||||
friend inline const_iterator operator +(size_t p, const const_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_iterator operator +(size_t p, const const_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const const_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const const_iterator & it) const {
|
||||||
inline bool operator !=(const const_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const const_iterator & it1, const const_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const const_iterator & it1, const const_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const const_iterator & it) const {
|
||||||
friend inline bool operator >(const const_iterator & it1, const const_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const const_iterator & it1, const const_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class reverse_iterator {
|
class reverse_iterator {
|
||||||
@@ -266,34 +429,94 @@ public:
|
|||||||
|
|
||||||
inline reverse_iterator(): parent(0), pos(0) {}
|
inline reverse_iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline T & operator *() {return (*parent)[pos];}
|
inline T & operator *() {
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
inline T & operator ->() {return (*parent)[pos];}
|
}
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline T & operator ->() {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline reverse_iterator & operator ++() {--pos; return *this;}
|
inline reverse_iterator & operator ++() {
|
||||||
inline reverse_iterator & operator ++(int) {const auto tmp = *this; --*this; return tmp;}
|
--pos;
|
||||||
inline reverse_iterator & operator --() {++pos; return *this;}
|
return *this;
|
||||||
inline reverse_iterator & operator --(int) {const auto tmp = *this; ++*this; return tmp;}
|
}
|
||||||
|
inline reverse_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator --() {
|
||||||
|
++pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline reverse_iterator & operator +=(const reverse_iterator & it) {pos -= it.pos; return *this;}
|
inline reverse_iterator & operator +=(const reverse_iterator & it) {
|
||||||
inline reverse_iterator & operator +=(size_t p) {pos -= p; return *this;}
|
pos -= it.pos;
|
||||||
inline reverse_iterator & operator -=(const reverse_iterator & it) {pos += it.pos; return *this;}
|
return *this;
|
||||||
inline reverse_iterator & operator -=(size_t p) {pos += p; return *this;}
|
}
|
||||||
|
inline reverse_iterator & operator +=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator -=(const reverse_iterator & it) {
|
||||||
|
pos += it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator -=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline reverse_iterator operator -(const reverse_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline reverse_iterator operator -(const reverse_iterator & it, size_t p) {
|
||||||
friend inline reverse_iterator operator -(size_t p, const reverse_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const reverse_iterator & it1, const reverse_iterator & it2) {return it2.pos - it1.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline reverse_iterator operator -(size_t p, const reverse_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it2.pos - it1.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline reverse_iterator operator +(const reverse_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline reverse_iterator operator +(const reverse_iterator & it, size_t p) {
|
||||||
friend inline reverse_iterator operator +(size_t p, const reverse_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline reverse_iterator operator +(size_t p, const reverse_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const reverse_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const reverse_iterator & it) const {
|
||||||
inline bool operator !=(const reverse_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const reverse_iterator & it) const {
|
||||||
friend inline bool operator >(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_reverse_iterator {
|
class const_reverse_iterator {
|
||||||
@@ -310,56 +533,273 @@ public:
|
|||||||
typedef std::random_access_iterator_tag iterator_category;
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
|
||||||
inline const_reverse_iterator(): parent(0), pos(0) {}
|
inline const_reverse_iterator(): parent(0), pos(0) {}
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline const_reverse_iterator & operator ++() {--pos; return *this;}
|
inline const_reverse_iterator & operator ++() {
|
||||||
inline const_reverse_iterator & operator ++(int) {const auto tmp = *this; --*this; return tmp;}
|
--pos;
|
||||||
inline const_reverse_iterator & operator --() {++pos; return *this;}
|
return *this;
|
||||||
inline const_reverse_iterator & operator --(int) {const auto tmp = *this; ++*this; return tmp;}
|
}
|
||||||
|
inline const_reverse_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator --() {
|
||||||
|
++pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline const_reverse_iterator & operator +=(const const_reverse_iterator & it) {pos -= it.pos; return *this;}
|
inline const_reverse_iterator & operator +=(const const_reverse_iterator & it) {
|
||||||
inline const_reverse_iterator & operator +=(size_t p) {pos -= p; return *this;}
|
pos -= it.pos;
|
||||||
inline const_reverse_iterator & operator -=(const const_reverse_iterator & it) {pos += it.pos; return *this;}
|
return *this;
|
||||||
inline const_reverse_iterator & operator -=(size_t p) {pos += p; return *this;}
|
}
|
||||||
|
inline const_reverse_iterator & operator +=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator -=(const const_reverse_iterator & it) {
|
||||||
|
pos += it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator -=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_reverse_iterator operator -(const const_reverse_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline const_reverse_iterator operator -(const const_reverse_iterator & it, size_t p) {
|
||||||
friend inline const_reverse_iterator operator -(size_t p, const const_reverse_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it2.pos - it1.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_reverse_iterator operator -(size_t p, const const_reverse_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it2.pos - it1.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_reverse_iterator operator +(const const_reverse_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline const_reverse_iterator operator +(const const_reverse_iterator & it, size_t p) {
|
||||||
friend inline const_reverse_iterator operator +(size_t p, const const_reverse_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_reverse_iterator operator +(size_t p, const const_reverse_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const const_reverse_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const const_reverse_iterator & it) const {
|
||||||
inline bool operator !=(const const_reverse_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const const_reverse_iterator & it) const {
|
||||||
friend inline bool operator >(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline iterator begin() {return iterator(this, 0);}
|
|
||||||
inline iterator end() {return iterator(this, pid_size);}
|
|
||||||
inline const_iterator begin() const {return const_iterator(this, 0);}
|
|
||||||
inline const_iterator end() const {return const_iterator(this, pid_size);}
|
|
||||||
inline reverse_iterator rbegin() {return reverse_iterator(this, pid_size - 1);}
|
|
||||||
inline reverse_iterator rend() {return reverse_iterator(this, -1);}
|
|
||||||
inline const_reverse_iterator rbegin() const {return const_reverse_iterator(this, pid_size - 1);}
|
|
||||||
inline const_reverse_iterator rend() const {return const_reverse_iterator(this, -1);}
|
|
||||||
|
|
||||||
inline size_t size() const {return pid_size;}
|
//! \~\brief
|
||||||
inline ssize_t size_s() const {return pid_size;}
|
//! \~english Iterator to the first element.
|
||||||
inline size_t length() const {return pid_size;}
|
//! \~russian Итератор на первый элемент.
|
||||||
inline size_t capacity() const {return pid_rsize;}
|
//! \~\details 
|
||||||
inline size_t _start() const {return pid_start;}
|
//!
|
||||||
inline bool isEmpty() const {return (pid_size == 0);}
|
//! \~english If the array is empty, the returned iterator is equal to \a end().
|
||||||
inline bool isNotEmpty() const {return (pid_size > 0);}
|
//! \~russian Если массив - пуст, возвращаемый итератор будет равен \a end().
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a end(), \a rbegin(), \a rend()
|
||||||
|
inline iterator begin() {
|
||||||
|
return iterator(this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Iterator to the element following the last element.
|
||||||
|
//! \~russian Итератор на элемент, следующий за последним элементом.
|
||||||
|
//! \~\details 
|
||||||
|
//!
|
||||||
|
//! \~english This element acts as a placeholder;
|
||||||
|
//! attempting to access it results in undefined behavior.
|
||||||
|
//! \~russian Этот элемент существует лишь условно,
|
||||||
|
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a begin(), \a rbegin(), \a rend()
|
||||||
|
inline iterator end() {
|
||||||
|
return iterator(this, pid_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const_iterator begin() const {
|
||||||
|
return const_iterator(this, 0);
|
||||||
|
}
|
||||||
|
inline const_iterator end() const {
|
||||||
|
return const_iterator(this, pid_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns a reverse iterator to the first element of the reversed array.
|
||||||
|
//! \~russian Обратный итератор на первый элемент.
|
||||||
|
//! \~\details 
|
||||||
|
//!
|
||||||
|
//! \~english It corresponds to the last element of the non-reversed array.
|
||||||
|
//! If the array is empty, the returned iterator is equal to \a rend().
|
||||||
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
|
//! Указывает на последний элемент.
|
||||||
|
//! Если массив пустой, то совпадает с итератором \a rend().
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a rend(), \a begin(), \a end()
|
||||||
|
inline reverse_iterator rbegin() {
|
||||||
|
return reverse_iterator(this, pid_size - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns a reverse iterator to the element
|
||||||
|
//! following the last element of the reversed array.
|
||||||
|
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
||||||
|
//! \~\details 
|
||||||
|
//!
|
||||||
|
//! \~english It corresponds to the element preceding the first element of the non-reversed array.
|
||||||
|
//! This element acts as a placeholder, attempting to access it results in undefined behavior.
|
||||||
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
|
//! Указывает на элемент, предшествующий первому элементу.
|
||||||
|
//! Этот элемент существует лишь условно,
|
||||||
|
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
||||||
|
//! \~\return \ref stl_iterators
|
||||||
|
//! \~\sa \a rbegin(), \a begin(), \a end()
|
||||||
|
inline reverse_iterator rend() {
|
||||||
|
return reverse_iterator(this, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const_reverse_iterator rbegin() const {
|
||||||
|
return const_reverse_iterator(this, pid_size - 1);
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator rend() const {
|
||||||
|
return const_reverse_iterator(this, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Number of elements in the container.
|
||||||
|
//! \~russian Количество элементов массива.
|
||||||
|
//! \~\sa \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
|
inline size_t size() const {
|
||||||
|
return pid_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Number of elements in the container as signed value.
|
||||||
|
//! \~russian Количество элементов массива в виде знакового числа.
|
||||||
|
//! \~\sa \a size(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
|
inline ssize_t size_s() const {
|
||||||
|
return pid_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Same as \a size().
|
||||||
|
//! \~russian Синоним \a size().
|
||||||
|
//! \~\sa \a size(), \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
|
inline size_t length() const {
|
||||||
|
return pid_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Number of elements that the container has currently allocated space for.
|
||||||
|
//! \~russian Количество элементов, для которого сейчас выделена память контейнером.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english To find out the actual number of items, use the function \a size().
|
||||||
|
//! \~russian Чтобы узнать фактическое количество элементов используйте функцию \a size().
|
||||||
|
//! \~\sa \a reserve(), \a size(), \a size_s()
|
||||||
|
inline size_t capacity() const {
|
||||||
|
return pid_rsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t _start() const {
|
||||||
|
return pid_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Checks if the container has no elements.
|
||||||
|
//! \~russian Проверяет пуст ли контейнер.
|
||||||
|
//! \~\return
|
||||||
|
//! \~english **true** if the container is empty, **false** otherwise
|
||||||
|
//! \~russian **true** если контейнер пуст, **false** иначе.
|
||||||
|
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
|
inline bool isEmpty() const {
|
||||||
|
return (pid_size == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Checks if the container has elements.
|
||||||
|
//! \~russian Проверяет не пуст ли контейнер.
|
||||||
|
//! \~\return
|
||||||
|
//! \~english **true** if the container is not empty, **false** otherwise
|
||||||
|
//! \~russian **true** если контейнер не пуст, **false** иначе.
|
||||||
|
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
|
inline bool isNotEmpty() const {
|
||||||
|
return (pid_size > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Tests whether at least one element in the array
|
||||||
|
//! passes the test implemented by the provided function `test`.
|
||||||
|
//! \~russian Проверяет, удовлетворяет ли какой-либо элемент массива условию,
|
||||||
|
//! заданному в передаваемой функции `test`.
|
||||||
|
//! \~\return
|
||||||
|
//! \~english **true** if, in the array,
|
||||||
|
//! it finds an element for which the provided function returns **true**;
|
||||||
|
//! otherwise it returns **false**. Always returns **false** if is empty.
|
||||||
|
//! \~russian **true** если хотя бы для одного элемента
|
||||||
|
//! передаваемая функция возвращает **true**, в остальных случаях **false**.
|
||||||
|
//! Метод возвращает **false** при любом условии для пустого массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<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
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a every(), \a contains(), \a etries(), \a forEach()
|
||||||
inline bool any(std::function<bool(const T & e)> test) const {
|
inline bool any(std::function<bool(const T & e)> test) const {
|
||||||
for (ssize_t i = pid_start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (test(pid_data[i])) return true;
|
if (test(pid_data[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Tests whether all elements in the array passes the test
|
||||||
|
//! implemented by the provided function `test`.
|
||||||
|
//! \~russian Проверяет, удовлетворяют ли все элементы массива условию,
|
||||||
|
//! заданному в передаваемой функции `test`.
|
||||||
|
//! \~\return
|
||||||
|
//! \~english **true** if, in the array,
|
||||||
|
//! it finds an element for which the provided function returns **true**;
|
||||||
|
//! otherwise it returns **false**. Always returns **true** if is empty.
|
||||||
|
//! \~russian **true** если для всех элементов передаваемая функция возвращает **true**,
|
||||||
|
//! в остальных случаях **false**.
|
||||||
|
//! Метод возвращает **true** при любом условии для пустого массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<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
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a any(), \a contains(), \a entries(), \a forEach()
|
||||||
inline bool every(std::function<bool(const T & e)> test) const {
|
inline bool every(std::function<bool(const T & e)> test) const {
|
||||||
for (ssize_t i = pid_start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (!test(pid_data[i])) return false;
|
if (!test(pid_data[i])) return false;
|
||||||
@@ -367,64 +807,248 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Full access to element by `index`.
|
||||||
|
//! \~russian Полный доступ к элементу по индексу `index`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Element index starts from `0`.
|
||||||
|
//! Element index must be in range from `0` to `size()-1`.
|
||||||
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Индекс элемента считается от `0`.
|
||||||
|
//! Индекс элемента должен лежать в пределах от `0` до `size()-1`.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 8, 9};
|
||||||
|
//! piCout << v[2]; // 8
|
||||||
|
//! v[2] = 5;
|
||||||
|
//! piCout << v; // {1, 2, 5, 9}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a at()
|
||||||
|
inline T & operator [](size_t index) {
|
||||||
|
return pid_data[pid_start + index];
|
||||||
|
}
|
||||||
|
inline const T & operator [](size_t index) const {
|
||||||
|
return pid_data[pid_start + index];
|
||||||
|
}
|
||||||
|
|
||||||
inline T & operator [](size_t index) {return pid_data[pid_start + index];}
|
//! \brief
|
||||||
inline const T & operator [](size_t index) const {return pid_data[pid_start + index];}
|
//! \~english Read only access to element by `index`.
|
||||||
inline const T & at(size_t index) const {return pid_data[pid_start + index];}
|
//! \~russian Доступ исключительно на чтение к элементу по индексу `index`.
|
||||||
inline T & back() {return pid_data[pid_start + pid_size - 1];}
|
//! \~\details
|
||||||
inline const T & back() const {return pid_data[pid_start + pid_size - 1];}
|
//! \~english Element index starts from `0`.
|
||||||
inline T & front() {return pid_data[pid_start];}
|
//! Element index must be in range from `0` to `size()-1`.
|
||||||
inline const T & front() const {return pid_data[pid_start];}
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Индекс элемента считается от `0`.
|
||||||
|
//! Индекс элемента должен лежать в пределах от `0` до `size()-1`.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
inline const T & at(size_t index) const {
|
||||||
|
return pid_data[pid_start + index];
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Last element.
|
||||||
|
//! \~russian Последний элемент массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Returns a reference to the last item in the array.
|
||||||
|
//! This function assumes that the array isn't empty.
|
||||||
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Возвращает ссылку на последний элемент в массиве.
|
||||||
|
//! Эта функция предполагает, что массив не пустой.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
inline T & back() {
|
||||||
|
return pid_data[pid_start + pid_size - 1];
|
||||||
|
}
|
||||||
|
inline const T & back() const {
|
||||||
|
return pid_data[pid_start + pid_size - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Last element.
|
||||||
|
//! \~russian Первый элемент массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Returns a reference to the last item in the array.
|
||||||
|
//! This function assumes that the array isn't empty.
|
||||||
|
//! Otherwise will be undefined behavior.
|
||||||
|
//! \~russian Возвращает ссылку на пенрвый элемент в массиве.
|
||||||
|
//! Эта функция предполагает, что массив не пустой.
|
||||||
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
|
inline T & front() {
|
||||||
|
return pid_data[pid_start];
|
||||||
|
}
|
||||||
|
inline const T & front() const {
|
||||||
|
return pid_data[pid_start];
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Compare operator with array `v`.
|
||||||
|
//! \~russian Оператор сравнения с массивом `v`.
|
||||||
inline bool operator ==(const PIDeque<T> & v) const {
|
inline bool operator ==(const PIDeque<T> & v) const {
|
||||||
if (pid_size != v.pid_size) return false;
|
if (pid_size != v.pid_size) return false;
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
for (size_t i = 0; i < pid_size; ++i) {
|
||||||
if (v[i] != (*this)[i]) {
|
if (v[i] != (*this)[i]) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool operator !=(const PIDeque<T> & v) const {return !(*this == v);}
|
|
||||||
inline bool operator <(const PIDeque<T> & v) const {
|
//! \brief
|
||||||
if (pid_size != v.pid_size) return pid_size < v.pid_size;
|
//! \~english Compare operator with array `v`.
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
//! \~russian Оператор сравнения с массивом `v`.
|
||||||
if ((*this)[i] != v[i]) return (*this)[i] < v[i];
|
inline bool operator !=(const PIDeque<T> & v) const {
|
||||||
}
|
return !(*this == v);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
inline bool operator >(const PIDeque<T> & v) const {
|
//! \~\brief
|
||||||
if (pid_size != v.pid_size) return pid_size > v.pid_size;
|
//! \~english Tests if element `e` exists in the array.
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
//! \~russian Проверяет наличие элемента `e` в массиве.
|
||||||
if ((*this)[i] != v[i]) return (*this)[i] > v[i];
|
//! \~\details
|
||||||
}
|
//! \~english Optional argument `start` - the position in this array at which to begin searching.
|
||||||
return false;
|
//! If the index is greater than or equal to the array's size,
|
||||||
}
|
//! **false** is returned, which means the array will not be searched.
|
||||||
inline bool contains(const T & e) const {
|
//! If the provided index value is a negative number,
|
||||||
for (ssize_t i = pid_start; i < pid_start + (ssize_t)pid_size; ++i) {
|
//! it is taken as the offset from the end of the array.
|
||||||
if (e == pid_data[i]) {
|
//! Note: if the provided index is negative,
|
||||||
return true;
|
//! the array is still searched from front to back.
|
||||||
}
|
//! Default: 0 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс в массиве, откуда будет начинаться поиск.
|
||||||
|
//! Если индекс больше или равен длине массива,
|
||||||
|
//! возвращается **false**, что означает, что массив даже не просматривается.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Если рассчитанный индекс все равно оказывается меньше 0, просматривается весь массив.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от начала к концу.
|
||||||
|
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<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, -99); // true
|
||||||
|
//! \endcode
|
||||||
|
//! \~\return
|
||||||
|
//! \~english **true** if the array contains an occurrence of element `e`,
|
||||||
|
//! otherwise it returns **false**.
|
||||||
|
//! \~russian **true** если элемент `e` присутствует в массиве,
|
||||||
|
//! в остальных случаях **false**.
|
||||||
|
//! \~\sa \a every(), \a any(), \a etries(), \a forEach()
|
||||||
|
inline bool contains(const T & e, ssize_t start = 0) const {
|
||||||
|
if (start < 0) {
|
||||||
|
start = pid_size + start;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
}
|
||||||
|
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
|
if (e == pid_data[i]) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Count elements equal `e` in the array.
|
||||||
|
//! \~russian Подсчитывает количество элементов, совпадающих с элементом `e` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `start` - the position in this array at which to begin searching.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! 0 is returned, which means the array will not be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from front to back.
|
||||||
|
//! Default: 0 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс в массиве, откуда будет начинаться поиск.
|
||||||
|
//! Если индекс больше или равен длине массива,
|
||||||
|
//! возвращается 0, что означает, что массив даже не просматривается.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Если рассчитанный индекс все равно оказывается меньше 0, просматривается весь массив.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от начала к концу.
|
||||||
|
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{2, 2, 4, 2, 6};
|
||||||
|
//! 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()
|
||||||
inline int etries(const T & e, size_t start = 0) const {
|
inline int etries(const T & e, size_t start = 0) const {
|
||||||
int ec = 0;
|
int ec = 0;
|
||||||
if (start >= pid_size) return ec;
|
if (start < 0) {
|
||||||
|
start = pid_size + start;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
}
|
||||||
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (e == pid_data[i]) ++ec;
|
if (e == pid_data[i]) ++ec;
|
||||||
}
|
}
|
||||||
return ec;
|
return ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Count elements in the array passes the test implemented by the provided function `test`.
|
||||||
|
//! \~russian Подсчитывает количество элементов в массиве,
|
||||||
|
//! проходящих по условию, заданному в передаваемой функции `test`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Optional argument `start` - the position in this array at which to begin searching.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! 0 is returned, which means the array will not be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from front to back.
|
||||||
|
//! Default: 0 (entire array is searched).
|
||||||
|
//! \~russian Перегруженная функция.
|
||||||
|
//! Опциональный аргумент `start` указывает на индекс в массиве, откуда будет начинаться поиск.
|
||||||
|
//! Если индекс больше или равен длине массива,
|
||||||
|
//! возвращается 0, что означает, что массив даже не просматривается.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Если рассчитанный индекс все равно оказывается меньше 0, просматривается весь массив.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от начала к концу.
|
||||||
|
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||||
|
//! \~\sa \a every(), \a any(), \a contains(), \a forEach(), \a indexWhere()
|
||||||
inline int etries(std::function<bool(const T & e)> test, size_t start = 0) const {
|
inline int etries(std::function<bool(const T & e)> test, size_t start = 0) const {
|
||||||
int ec = 0;
|
int ec = 0;
|
||||||
if (start >= pid_size) return ec;
|
if (start < 0) {
|
||||||
|
start = pid_size + start;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
}
|
||||||
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (test(pid_data[i])) ++ec;
|
if (test(pid_data[i])) ++ec;
|
||||||
}
|
}
|
||||||
return ec;
|
return ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns the first index at which a given element `e`
|
||||||
|
//! can be found in the array, or `-1` if it is not present.
|
||||||
|
//! \~russian Возвращает первый индекс, по которому данный элемент `e`
|
||||||
|
//! может быть найден в массиве или `-1`, если такого индекса нет.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `start` - the position in this array at which to begin searching.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! `-1` is returned, which means the array will not be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from front to back.
|
||||||
|
//! Default: 0 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс в массиве, откуда будет начинаться поиск.
|
||||||
|
//! Если индекс больше или равен длине массива,
|
||||||
|
//! возвращается `-1`, что означает, что массив даже не просматривается.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Если рассчитанный индекс все равно оказывается меньше 0, просматривается весь массив.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от начала к концу.
|
||||||
|
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{2, 5, 9};
|
||||||
|
//! piCout << v.indexOf(2); // 0
|
||||||
|
//! piCout << v.indexOf(7); // -1
|
||||||
|
//! piCout << v.indexOf(9, 2); // 2
|
||||||
|
//! piCout << v.indexOf(2, -1); // -1
|
||||||
|
//! piCout << v.indexOf(2, -3); // 0
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a indexWhere(), \a lastIndexOf(), \a lastIndexWhere(), \a contains()
|
||||||
inline ssize_t indexOf(const T & e, size_t start = 0) const {
|
inline ssize_t indexOf(const T & e, size_t start = 0) const {
|
||||||
if (start >= pid_size) return -1;
|
if (start < 0) {
|
||||||
|
start = pid_size + start;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
}
|
||||||
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (e == pid_data[i]) {
|
if (e == pid_data[i]) {
|
||||||
return i - pid_start;
|
return i - pid_start;
|
||||||
@@ -432,8 +1056,41 @@ public:
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns the first index passes the test implemented by the provided function `test`,
|
||||||
|
//! or `-1` if it is not present.
|
||||||
|
//! can be found in the array, or `-1` if it is not present.
|
||||||
|
//! \~russian Возвращает первый индекс элемента проходящего по условию,
|
||||||
|
//! заданному в передаваемой функции `test`, или `-1`, если таких элементов нет.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `start` - the position in this array at which to begin searching.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! `-1` is returned, which means the array will not be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from front to back.
|
||||||
|
//! Default: 0 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс в массиве, откуда будет начинаться поиск.
|
||||||
|
//! Если индекс больше или равен длине массива,
|
||||||
|
//! возвращается `-1`, что означает, что массив даже не просматривается.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Если рассчитанный индекс все равно оказывается меньше 0, просматривается весь массив.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от начала к концу.
|
||||||
|
//! Значение по умолчанию равно 0, что означает, что просматривается весь массив.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<PIString> v{"do", "re", "mi", "re"};
|
||||||
|
//! piCout << v.indexWhere([](const PIString & s){return s.startsWith('r');}); // 1
|
||||||
|
//! piCout << v.indexWhere([](const PIString & s){return s.startsWith('r');}, 2); // 3
|
||||||
|
//! piCout << v.indexWhere([](const PIString & s){return s.startsWith('k');}); // -1
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a indexOf(), \a lastIndexOf(), \a lastIndexWhere(), \a contains()
|
||||||
inline ssize_t indexWhere(std::function<bool(const T & e)> test, size_t start = 0) const {
|
inline ssize_t indexWhere(std::function<bool(const T & e)> test, size_t start = 0) const {
|
||||||
if (start >= pid_size) return -1;
|
if (start < 0) {
|
||||||
|
start = pid_size + start;
|
||||||
|
if (start < 0) start = 0;
|
||||||
|
}
|
||||||
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
for (ssize_t i = pid_start + start; i < pid_start + (ssize_t)pid_size; ++i) {
|
||||||
if (test(pid_data[i])) {
|
if (test(pid_data[i])) {
|
||||||
return i - pid_start;
|
return i - pid_start;
|
||||||
@@ -441,9 +1098,45 @@ public:
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns the last index at which a given element `e`
|
||||||
|
//! can be found in the array, or `-1` if it is not present.
|
||||||
|
//! \~russian Возвращает последний индекс, по которому данный элемент `e`
|
||||||
|
//! может быть найден в массиве или `-1`, если такого индекса нет.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `start` - the position in this array
|
||||||
|
//! at which to start searching backwards.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! causes the whole array to be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Therefore, if calculated index less than 0,
|
||||||
|
//! the array is not searched, and the method returns `-1`.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from back to front.
|
||||||
|
//! Default: -1 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс
|
||||||
|
//! c которого начинать поиск в обратном направлении.
|
||||||
|
//! Если индекс больше или равен длине массива, просматривается весь массив.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от конца к началу.
|
||||||
|
//! Если рассчитанный индекс оказывается меньше 0, массив даже не просматривается.
|
||||||
|
//! Значение по умолчанию равно `-1`, что равно индексу последнего элемента
|
||||||
|
//! и означает, что просматривается весь массив.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<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, -300); // -1
|
||||||
|
//! 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 {
|
inline ssize_t lastIndexOf(const T & e, ssize_t start = -1) const {
|
||||||
if (start < 0) start = pid_size - 1;
|
if (start >= size_s()) start = pid_size - 1;
|
||||||
else start = piMin<ssize_t>(pid_size - 1, start);
|
if (start < 0) start = pid_size + start;
|
||||||
for (ssize_t i = pid_start + start; i >= pid_start; --i) {
|
for (ssize_t i = pid_start + start; i >= pid_start; --i) {
|
||||||
if (e == pid_data[i]) {
|
if (e == pid_data[i]) {
|
||||||
return i - pid_start;
|
return i - pid_start;
|
||||||
@@ -451,9 +1144,36 @@ public:
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns the last index passes the test implemented by the provided function `test`,
|
||||||
|
//! or `-1` if it is not present.
|
||||||
|
//! \~russian Возвращает последний индекс элемента проходящего по условию,
|
||||||
|
//! заданному в передаваемой функции `test`, или `-1`, если таких элементов нет.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `start` - the position in this array
|
||||||
|
//! at which to start searching backwards.
|
||||||
|
//! If the index is greater than or equal to the array's size,
|
||||||
|
//! causes the whole array to be searched.
|
||||||
|
//! If the provided index value is a negative number,
|
||||||
|
//! it is taken as the offset from the end of the array.
|
||||||
|
//! Therefore, if calculated index less than 0,
|
||||||
|
//! the array is not searched, and the method returns `-1`.
|
||||||
|
//! Note: if the provided index is negative,
|
||||||
|
//! the array is still searched from back to front.
|
||||||
|
//! Default: -1 (entire array is searched).
|
||||||
|
//! \~russian Опциональный аргумент `start` указывает на индекс
|
||||||
|
//! c которого начинать поиск в обратном направлении.
|
||||||
|
//! Если индекс больше или равен длине массива, просматривается весь массив.
|
||||||
|
//! Если индекс является отрицательным числом, он трактуется как смещение с конца массива.
|
||||||
|
//! Обратите внимание: если индекс отрицателен, массив всё равно просматривается от конца к началу.
|
||||||
|
//! Если рассчитанный индекс оказывается меньше 0, массив даже не просматривается.
|
||||||
|
//! Значение по умолчанию равно `-1`, что равно индексу последнего элемента
|
||||||
|
//! и означает, что просматривается весь массив.
|
||||||
|
//! \~\sa \a indexOf(), \a lastIndexOf(), \a indexWhere(), \a contains()
|
||||||
inline ssize_t lastIndexWhere(std::function<bool(const T & e)> test, ssize_t start = -1) const {
|
inline ssize_t lastIndexWhere(std::function<bool(const T & e)> test, ssize_t start = -1) const {
|
||||||
if (start < 0) start = pid_size - 1;
|
if (start >= size_s()) start = pid_size - 1;
|
||||||
else start = piMin<ssize_t>(pid_size - 1, start);
|
if (start < 0) start = pid_size + start;
|
||||||
for (ssize_t i = pid_start + start; i >= pid_start; --i) {
|
for (ssize_t i = pid_start + start; i >= pid_start; --i) {
|
||||||
if (test(pid_data[i])) {
|
if (test(pid_data[i])) {
|
||||||
return i - pid_start;
|
return i - pid_start;
|
||||||
@@ -462,15 +1182,76 @@ public:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline T * data(size_t index = 0) {return &(pid_data[pid_start + index]);}
|
//! \~\brief
|
||||||
inline const T * data(size_t index = 0) const {return &(pid_data[pid_start + index]);}
|
//! \~english Pointer to array
|
||||||
|
//! \~russian Указатель на память массива
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Optional argument `index` the position in this array,
|
||||||
|
//! where is pointer. Default: start of array.
|
||||||
|
//! \~russian Опциональный аргумент `index` указывает на индекс c которого брать указатель.
|
||||||
|
//! По умолчанию указывает на начало массива.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<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}
|
||||||
|
//! \endcode
|
||||||
|
inline T * data(size_t index = 0) {
|
||||||
|
return &(pid_data[pid_start + index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Read only pointer to array
|
||||||
|
//! \~russian Указатель на память массива только для чтения.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The pointer can be used to access and modify the items in the array.
|
||||||
|
//! The pointer remains valid as long as the array isn't reallocated.
|
||||||
|
//! Optional argument `index` the position in this array,
|
||||||
|
//! where is pointer. Default: start of array.
|
||||||
|
//! \~russian Указатель можно использовать для доступа и изменения элементов в массиве.
|
||||||
|
//! Указатель остается действительным только до тех пор, пока массив не будет перераспределен.
|
||||||
|
//! Опциональный аргумент `index` указывает на индекс c которого брать указатель.
|
||||||
|
//! По умолчанию указывает на начало массива.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 3, 5};
|
||||||
|
//! int a[3];
|
||||||
|
//! memcpy(a, v.data(), a.size() * sizeof(int));
|
||||||
|
//! piCout << a[0] << a[1] << a[2]; // 1 3 5
|
||||||
|
//! \endcode
|
||||||
|
inline const T * data(size_t index = 0) const {
|
||||||
|
return &(pid_data[pid_start + index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Creates sub-array of this array.
|
||||||
|
//! \~russian Создает подмассив, то есть кусок из текущего массива.
|
||||||
|
//! \~english
|
||||||
|
//! \param index - index of this array where sub-array starts
|
||||||
|
//! \param count - sub-array size
|
||||||
|
//! \~russian
|
||||||
|
//! \param index - индекс в текущем массиве, откуда начинётся подмассив
|
||||||
|
//! \param count - размер подмассива
|
||||||
|
//! \~\details
|
||||||
|
//! \~english
|
||||||
|
//! Index must be in range from `0` to `size()-1`.
|
||||||
|
//! If sub-array size more than this array size, than ends early.
|
||||||
|
//! \~russian
|
||||||
|
//! Индекс начала должен лежать в диапазоне от `0` до `size()-1`.
|
||||||
|
//! Если заданный размер подмассива превышает размер текущего массива,
|
||||||
|
//! то вернется подмассив меншего размера (`size()-index-1`).
|
||||||
PIDeque<T> getRange(size_t index, size_t count) const {
|
PIDeque<T> getRange(size_t index, size_t count) const {
|
||||||
if (index >= pid_size || count == 0) return PIDeque<T>();
|
if (index >= pid_size || count == 0) return PIDeque<T>();
|
||||||
if (index + count > pid_size) count = pid_size - index;
|
if (index + count > pid_size) count = pid_size - index;
|
||||||
return PIDeque(&(pid_data[pid_start + index]), count);
|
return PIDeque(&(pid_data[pid_start + index]), count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Clear array, remove all elements.
|
||||||
|
//! \~russian Очищает массив, удаляет все элементы.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Note: reserved memory will not be released.
|
||||||
|
//! \~russian Замечание: зарезервированная память не освободится.
|
||||||
|
//! \~\sa \a resize()
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
!std::is_trivially_copyable<T1>::value
|
!std::is_trivially_copyable<T1>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
@@ -488,14 +1269,35 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PIDeque<T> & fill(const T & f = T()) {
|
//! \~\brief
|
||||||
|
//! \~english Assigns element 'e' to all items in the array.
|
||||||
|
//! \~russian Заполняет весь массив копиями элемента 'e'.
|
||||||
|
//! \~\details
|
||||||
|
//! \code
|
||||||
|
//! PIDeque<int> v{1, 3, 5};
|
||||||
|
//! v.fill(7);
|
||||||
|
//! piCout << v; // {7, 7, 7}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a resize()
|
||||||
|
inline PIDeque<T> & fill(const T & e = T()) {
|
||||||
deleteT(pid_data + pid_start, pid_size);
|
deleteT(pid_data + pid_start, pid_size);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, pid_size)
|
PIINTROSPECTION_CONTAINER_USED(T, pid_size)
|
||||||
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
elementNew(pid_data + i, f);
|
elementNew(pid_data + i, e);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Assigns result of function 'f(size_t i)' to all items in the array.
|
||||||
|
//! \~russian Заполняет весь массив результатом вызова функции 'f(size_t i)'.
|
||||||
|
//! \~\details
|
||||||
|
//! \code
|
||||||
|
//! PIDeque<int> v{1, 3, 5};
|
||||||
|
//! v.fill([](size_t i){return i*2;});
|
||||||
|
//! piCout << v; // {0, 2, 4}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a resize()
|
||||||
inline PIDeque<T> & fill(std::function<T(size_t i)> f) {
|
inline PIDeque<T> & fill(std::function<T(size_t i)> f) {
|
||||||
deleteT(pid_data + pid_start, pid_size);
|
deleteT(pid_data + pid_start, pid_size);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, pid_size)
|
PIINTROSPECTION_CONTAINER_USED(T, pid_size)
|
||||||
@@ -504,23 +1306,47 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline PIDeque<T> & assign(const T & f = T()) {return fill(f);}
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Same as \a fill().
|
||||||
|
//! \~russian Тоже самое что и \a fill().
|
||||||
|
//! \~\sa \a fill(), \a resize()
|
||||||
|
inline PIDeque<T> & assign(const T & e = T()) {
|
||||||
|
return fill(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english First does `resize(new_size)` then `fill(e)`.
|
||||||
|
//! \~russian Сначала делает `resize(new_size)` затем `fill(e)`.
|
||||||
|
//! \~\sa \a fill(), \a resize()
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
!std::is_trivially_copyable<T1>::value
|
!std::is_trivially_copyable<T1>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
inline PIDeque<T> & assign(size_t new_size, const T & f) {
|
inline PIDeque<T> & assign(size_t new_size, const T & e) {
|
||||||
resize(new_size);
|
resize(new_size);
|
||||||
return fill(f);
|
return fill(e);
|
||||||
}
|
}
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
std::is_trivially_copyable<T1>::value
|
std::is_trivially_copyable<T1>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
inline PIDeque<T> & assign(size_t new_size, const T & f) {
|
inline PIDeque<T> & assign(size_t new_size, const T & e) {
|
||||||
_resizeRaw(new_size);
|
_resizeRaw(new_size);
|
||||||
return fill(f);
|
return fill(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PIDeque<T> & resize(size_t new_size, const T & f = T()) {
|
//! \~\brief
|
||||||
|
//! \~english Sets size of the array, new elements are copied from `e`.
|
||||||
|
//! \~russian Устанавливает размер массива, новые элементы копируются из `e`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If `new_size` is greater than the current \a size(),
|
||||||
|
//! elements are added to the end; the new elements are initialized from `e`.
|
||||||
|
//! If `new_size` is less than the current \a size(), elements are removed from the end.
|
||||||
|
//! \~russian Если `new_size` больше чем текущий размер массива \a size(),
|
||||||
|
//! новые элементы добавляются в конец массива и создаются из `e`.
|
||||||
|
//! Если `new_size` меньше чем текущий размер массива \a size(),
|
||||||
|
//! лишние элементы удаляются с конца массива.
|
||||||
|
//! \~\sa \a size(), \a clear()
|
||||||
|
inline PIDeque<T> & resize(size_t new_size, const T & e = T()) {
|
||||||
if (new_size < pid_size) {
|
if (new_size < pid_size) {
|
||||||
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
||||||
pid_size = new_size;
|
pid_size = new_size;
|
||||||
@@ -533,11 +1359,24 @@ public:
|
|||||||
alloc_forward(new_size);
|
alloc_forward(new_size);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
||||||
for (size_t i = os + pid_start; i < new_size + pid_start; ++i) {
|
for (size_t i = os + pid_start; i < new_size + pid_start; ++i) {
|
||||||
elementNew(pid_data + i, f);
|
elementNew(pid_data + i, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Sets size of the array, new elements created by function `f(size_t i)`.
|
||||||
|
//! \~russian Устанавливает размер массива, новые элементы создаются функцией `f(size_t i)`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If `new_size` is greater than the current \a size(),
|
||||||
|
//! elements are added to the end; the new elements created by function `f(size_t i)`.
|
||||||
|
//! If `new_size` is less than the current \a size(), elements are removed from the end.
|
||||||
|
//! \~russian Если `new_size` больше чем текущий размер массива \a size(),
|
||||||
|
//! новые элементы добавляются в конец массива и функцией `f(size_t i)`.
|
||||||
|
//! Если `new_size` меньше чем текущий размер массива \a size(),
|
||||||
|
//! лишние элементы удаляются с конца массива.
|
||||||
|
//! \~\sa \a size(), \a clear()
|
||||||
inline PIDeque<T> & resize(size_t new_size, std::function<T(size_t i)> f) {
|
inline PIDeque<T> & resize(size_t new_size, std::function<T(size_t i)> f) {
|
||||||
if (new_size < pid_size) {
|
if (new_size < pid_size) {
|
||||||
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
||||||
@@ -571,6 +1410,25 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void _copyRaw(T * dst, const T * src, size_t size) {
|
||||||
|
newT(dst, src, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Attempts to allocate memory for at least `new_size` elements.
|
||||||
|
//! \~russian Резервируется память под как минимум `new_size` элементов.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If you know in advance how large the array will be,
|
||||||
|
//! you should call this function to prevent reallocations and memory fragmentation.
|
||||||
|
//! If `new_size` is greater than the current \a capacity(),
|
||||||
|
//! new storage is allocated, otherwise the function does nothing.
|
||||||
|
//! This function does not change the \a size() of the array.
|
||||||
|
//! \~russian Если вы заранее знаете, насколько велик будет массив,
|
||||||
|
//! вы можете вызвать эту функцию, чтобы предотвратить перераспределение и фрагментацию памяти.
|
||||||
|
//! Если размер `new_size` больше чем выделенная память \a capacity(),
|
||||||
|
//! то произойдёт выделение новой памяти и перераспределение массива.
|
||||||
|
//! Эта функция не изменяет количество элементов в массиве \a size().
|
||||||
|
//! \~\sa \a size(), \a capacity(), \a resize()
|
||||||
inline PIDeque<T> & reserve(size_t new_size) {
|
inline PIDeque<T> & reserve(size_t new_size) {
|
||||||
if (new_size <= pid_rsize) return *this;
|
if (new_size <= pid_rsize) return *this;
|
||||||
size_t os = pid_size;
|
size_t os = pid_size;
|
||||||
@@ -579,6 +1437,18 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Inserts value `e` at `index` position in the array.
|
||||||
|
//! \~russian Вставляет значение `e` в позицию `index` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The index must be greater than 0 and less than or equal to \a size().
|
||||||
|
//! \~russian Индекс должен быть больше 0 и меньше или равен \a size().
|
||||||
|
//! \code
|
||||||
|
//! PIDeque<int> v{1, 3, 5};
|
||||||
|
//! v.insert(2, 7);
|
||||||
|
//! piCout << v; // {1, 3, 7, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||||
inline PIDeque<T> & insert(size_t index, const T & e = T()) {
|
inline PIDeque<T> & insert(size_t index, const T & e = T()) {
|
||||||
if (index == pid_size) return push_back(e);
|
if (index == pid_size) return push_back(e);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||||
@@ -598,6 +1468,14 @@ public:
|
|||||||
elementNew(pid_data + pid_start + index, e);
|
elementNew(pid_data + pid_start + index, e);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Inserts value `e` at `index` position in the array.
|
||||||
|
//! \~russian Вставляет значение `e` в позицию `index` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The index must be greater than 0 and less than or equal to \a size().
|
||||||
|
//! \~russian Индекс должен быть больше 0 и меньше или равен \a size().
|
||||||
|
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||||
inline PIDeque<T> & insert(size_t index, T && e) {
|
inline PIDeque<T> & insert(size_t index, T && e) {
|
||||||
if (index == pid_size) return push_back(e);
|
if (index == pid_size) return push_back(e);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
PIINTROSPECTION_CONTAINER_USED(T, 1)
|
||||||
@@ -617,31 +1495,78 @@ public:
|
|||||||
elementNew(pid_data + pid_start + index, std::move(e));
|
elementNew(pid_data + pid_start + index, std::move(e));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
|
|
||||||
if (other.isEmpty()) return *this;
|
//! \~\brief
|
||||||
|
//! \~english Inserts array `v` at `index` position in the array.
|
||||||
|
//! \~russian Вставляет массив `v` в позицию `index` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The index must be greater than or equal to 0 and less than or equal to \a size().
|
||||||
|
//! \~russian Индекс должен быть больше или равен 0 и меньше или равен \a size().
|
||||||
|
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||||
|
inline PIDeque<T> & insert(size_t index, const PIDeque<T> & v) {
|
||||||
|
if (v.isEmpty()) return *this;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (&other == this) {
|
if (&v == this) {
|
||||||
printf("error with PIDeque<%s>::insert\n", __PIP_TYPENAME__(T));
|
printf("error with PIDeque<%s>::insert\n", __PIP_TYPENAME__(T));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
assert(&other != this);
|
assert(&v != this);
|
||||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||||
if (dir) {
|
if (dir) {
|
||||||
ssize_t os = pid_size - index;
|
ssize_t os = pid_size - index;
|
||||||
alloc_forward(pid_size + other.pid_size);
|
alloc_forward(pid_size + v.pid_size);
|
||||||
if (os > 0) {
|
if (os > 0) {
|
||||||
memmove((void*)(&(pid_data[index + pid_start + other.pid_size])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
memmove((void*)(&(pid_data[index + pid_start + v.pid_size])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alloc_backward(pid_size + other.pid_size, -other.pid_size);
|
alloc_backward(pid_size + v.pid_size, -v.pid_size);
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + other.pid_size])), index * sizeof(T));
|
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + v.pid_size])), index * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size);
|
newT(pid_data + pid_start + index, v.pid_data + v.pid_start, v.pid_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Inserts the given elements at `index` position in the array.
|
||||||
|
//! \~russian Вставляет элементы в позицию `index` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The index must be greater than or equal to 0 and less than or equal to \a size().
|
||||||
|
//! Inserts the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Индекс должен быть больше или равен 0 и меньше или равен \a size().
|
||||||
|
//! Вставляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||||
|
inline PIDeque<T> & insert(size_t index, std::initializer_list<T> init_list) {
|
||||||
|
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||||
|
if (dir) {
|
||||||
|
ssize_t os = pid_size - index;
|
||||||
|
alloc_forward(pid_size + init_list.size());
|
||||||
|
if (os > 0) {
|
||||||
|
memmove((void*)(&(pid_data[index + pid_start + init_list.size()])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alloc_backward(pid_size + init_list.size(), -init_list.size());
|
||||||
|
if (index > 0) {
|
||||||
|
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + init_list.size()])), index * sizeof(T));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newT(pid_data + pid_start + index, init_list.begin(), init_list.size());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Removes `count` elements from the middle of the array, starting at `index` position.
|
||||||
|
//! \~russian Удаляет элементы из массива, начиная с позиции `index`, в количестве `count`.
|
||||||
|
//! \~\details
|
||||||
|
//! \code
|
||||||
|
//! PIDeque<int> v{1, 3, 7, 5};
|
||||||
|
//! v.remove(1, 2);
|
||||||
|
//! piCout << v; // {1, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a resize(), \a insert(), \a removeOne(), \a removeAll(), \a removeWhere()
|
||||||
inline PIDeque<T> & remove(size_t index, size_t count = 1) {
|
inline PIDeque<T> & remove(size_t index, size_t count = 1) {
|
||||||
if (count == 0) return *this;
|
if (count == 0) return *this;
|
||||||
if (index + count >= pid_size) {
|
if (index + count >= pid_size) {
|
||||||
@@ -664,6 +1589,12 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Swaps array `v` other with this array.
|
||||||
|
//! \~russian Меняет местами массив `v` с этим массивом.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english This operation is very fast and never fails.
|
||||||
|
//! \~russian Эта операция выполняется мгновенно без копирования памяти и никогда не дает сбоев.
|
||||||
inline void swap(PIDeque<T> & other) {
|
inline void swap(PIDeque<T> & other) {
|
||||||
piSwap<T*>(pid_data, other.pid_data);
|
piSwap<T*>(pid_data, other.pid_data);
|
||||||
piSwap<size_t>(pid_size, other.pid_size);
|
piSwap<size_t>(pid_size, other.pid_size);
|
||||||
@@ -733,6 +1664,57 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Reverses this array.
|
||||||
|
//! \~russian Обращает порядок следования элементов этого массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english This method reverses an array [in place](https://en.wikipedia.org/wiki/In-place_algorithm).
|
||||||
|
//! The first array element becomes the last, and the last array element becomes the first.
|
||||||
|
//! The reverse method transposes the elements of the calling array object in place,
|
||||||
|
//! mutating the array, and returning a reference to the array.
|
||||||
|
//! \~russian Метод reverse() на месте переставляет элементы массива,
|
||||||
|
//! на котором он был вызван, изменяет массив и возвращает ссылку на него.
|
||||||
|
//! Первый элемент массива становится последним, а последний — первым.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 3, 7, 5};
|
||||||
|
//! v.reverse();
|
||||||
|
//! piCout << v; // {5, 7, 3, 1}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a reversed()
|
||||||
|
inline PIDeque<T> & reverse() {
|
||||||
|
size_t s2 = pid_size/2;
|
||||||
|
for (size_t i = 0; i < s2; ++i) {
|
||||||
|
piSwap<T>(pid_data[pid_start+i], pid_data[pid_start+pid_size-i-1]);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Returns reversed array.
|
||||||
|
//! \~russian Возвращает перевернутый массив.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Returns a copy of the array with elements in reverse order.
|
||||||
|
//! The first array element becomes the last, and the last array element becomes the first.
|
||||||
|
//! \~russian Возвращает копию массива с элементами в обратном порядке.
|
||||||
|
//! Первый элемент массива становится последним, а последний — первым.
|
||||||
|
//! \~\sa \a reverse()
|
||||||
|
inline PIDeque<T> reversed() const {
|
||||||
|
PIDeque<T> ret(*this);
|
||||||
|
return ret.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\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 PIDeque<T> & enlarge(llong pid_size) {
|
inline PIDeque<T> & enlarge(llong pid_size) {
|
||||||
llong ns = size_s() + pid_size;
|
llong ns = size_s() + pid_size;
|
||||||
if (ns <= 0) clear();
|
if (ns <= 0) clear();
|
||||||
@@ -740,6 +1722,16 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Remove no more than one element equal `e`.
|
||||||
|
//! \~russian Удаляет первый элемент, который равен элементу `e`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{3, 2, 5, 2, 7};
|
||||||
|
//! v.removeOne(2);
|
||||||
|
//! piCout << v; // {3, 5, 2, 7}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a remove(), \a removeAll(), \a removeWhere()
|
||||||
inline PIDeque<T> & removeOne(const T & e) {
|
inline PIDeque<T> & removeOne(const T & e) {
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
for (size_t i = 0; i < pid_size; ++i) {
|
||||||
if (pid_data[i + pid_start] == e) {
|
if (pid_data[i + pid_start] == e) {
|
||||||
@@ -749,6 +1741,17 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Remove all elements equal `e`.
|
||||||
|
//! \~russian Удаляет все элементы, равные элементу `e`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{3, 2, 5, 2, 7};
|
||||||
|
//! v.removeAll(2);
|
||||||
|
//! piCout << v; // {3, 5, 7}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||||
inline PIDeque<T> & removeAll(const T & e) {
|
inline PIDeque<T> & removeAll(const T & e) {
|
||||||
for (ssize_t i = 0; i < ssize_t(pid_size); ++i) {
|
for (ssize_t i = 0; i < ssize_t(pid_size); ++i) {
|
||||||
if (pid_data[i + pid_start] == e) {
|
if (pid_data[i + pid_start] == e) {
|
||||||
@@ -758,6 +1761,19 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Remove all elements in the array
|
||||||
|
//! passes the test implemented by the provided function `test`.
|
||||||
|
//! \~russian Удаляет все элементы, удовлетворяющие условию,
|
||||||
|
//! заданному в передаваемой функции `test`.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{3, 2, 5, 2, 7};
|
||||||
|
//! v.removeWhere([](const int & i){return i > 2;});
|
||||||
|
//! piCout << v; // {2, 2}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||||
inline PIDeque<T> & removeWhere(std::function<bool(const T & e)> test) {
|
inline PIDeque<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||||
for (ssize_t i = 0; i < ssize_t(pid_size); ++i) {
|
for (ssize_t i = 0; i < ssize_t(pid_size); ++i) {
|
||||||
if (test(pid_data[i + pid_start])) {
|
if (test(pid_data[i + pid_start])) {
|
||||||
@@ -768,21 +1784,78 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If size() is less than capacity(), which is most often
|
||||||
|
//! then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
|
//! If the new size() is greater than capacity()
|
||||||
|
//! then all iterators and references
|
||||||
|
//! (including the past-the-end iterator) are invalidated.
|
||||||
|
//! Otherwise only the past-the-end iterator is invalidated.
|
||||||
|
//! \~russian Если size() меньше capacity(), что чаше всего,
|
||||||
|
//! то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
|
//! Если новый size() больше, чем capacity(),
|
||||||
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
|
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
||||||
|
//! остаются в рабочем состоянии.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.push_back(4);
|
||||||
|
//! v.push_back(5);
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a push_front(), \a append(), \a prepend(), \a insert()
|
||||||
inline PIDeque<T> & push_back(const T & e) {
|
inline PIDeque<T> & push_back(const T & e) {
|
||||||
alloc_forward(pid_size + 1);
|
alloc_forward(pid_size + 1);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||||
elementNew(pid_data + pid_start + pid_size - 1, e);
|
elementNew(pid_data + pid_start + pid_size - 1, e);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\sa \a push_back()
|
||||||
inline PIDeque<T> & push_back(T && e) {
|
inline PIDeque<T> & push_back(T && e) {
|
||||||
alloc_forward(pid_size + 1);
|
alloc_forward(pid_size + 1);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
PIINTROSPECTION_CONTAINER_USED(T, 1);
|
||||||
elementNew(pid_data + pid_start + pid_size - 1, std::move(e));
|
elementNew(pid_data + pid_start + pid_size - 1, std::move(e));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline PIDeque<T> & append(const T & e) {return push_back(e);}
|
|
||||||
inline PIDeque<T> & append(T && e) {return push_back(std::move(e));}
|
//! \brief
|
||||||
inline PIDeque<T> & append(const PIDeque<T> & v) {
|
//! \~english Appends the given elements to the end of the array.
|
||||||
|
//! \~russian Добавляет элементы в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a push_back()
|
||||||
|
inline PIDeque<T> & push_back(std::initializer_list<T> init_list) {
|
||||||
|
size_t ps = pid_size;
|
||||||
|
alloc_forward(pid_size + init_list.size());
|
||||||
|
newT(pid_data + pid_start + ps, init_list.begin(), init_list.size());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given array `v` to the end of the array.
|
||||||
|
//! \~russian Добавляет массив `v` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\sa \a push_back()
|
||||||
|
inline PIDeque<T> & push_back(const PIDeque<T> & v) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (&v == this) {
|
if (&v == this) {
|
||||||
printf("error with PIDeque<%s>::append\n", __PIP_TYPENAME__(T));
|
printf("error with PIDeque<%s>::append\n", __PIP_TYPENAME__(T));
|
||||||
@@ -794,23 +1867,352 @@ public:
|
|||||||
newT(pid_data + ps + pid_start, v.pid_data + v.pid_start, v.pid_size);
|
newT(pid_data + ps + pid_start, v.pid_data + v.pid_start, v.pid_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
inline PIDeque<T> & operator <<(const T & e) {return push_back(e);}
|
|
||||||
inline PIDeque<T> & operator <<(T && e) {return push_back(std::move(e));}
|
|
||||||
inline PIDeque<T> & operator <<(const PIDeque<T> & v) {return append(v);}
|
|
||||||
|
|
||||||
inline PIDeque<T> & push_front(const T & e) {insert(0, e); return *this;}
|
//! \brief
|
||||||
inline PIDeque<T> & push_front(T && e) {insert(0, std::move(e)); return *this;}
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
inline PIDeque<T> & prepend(const T & e) {return push_front(e);}
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
inline PIDeque<T> & prepend(T && e) {return push_front(std::move(e));}
|
//! \~\details
|
||||||
|
//! \~english If size() is less than capacity(), which is most often
|
||||||
|
//! then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
|
//! If the new size() is greater than capacity()
|
||||||
|
//! then all iterators and references
|
||||||
|
//! (including the past-the-end iterator) are invalidated.
|
||||||
|
//! Otherwise only the past-the-end iterator is invalidated.
|
||||||
|
//! \~russian Если size() меньше capacity(), что чаше всего,
|
||||||
|
//! то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
|
//! Если новый size() больше, чем capacity(),
|
||||||
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
|
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
||||||
|
//! остаются в рабочем состоянии.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.append(4);
|
||||||
|
//! v.append(5);
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a prepend(), \a push_front(), \a push_back(), \a insert()
|
||||||
|
inline PIDeque<T> & append(const T & e) {
|
||||||
|
return push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
inline PIDeque<T> & pop_back() {if (pid_size == 0) return *this; resize(pid_size - 1); return *this;}
|
//! \brief
|
||||||
inline PIDeque<T> & pop_front() {if (pid_size == 0) return *this; remove(0); return *this;}
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & append(T && e) {
|
||||||
|
return push_back(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
inline T take_back() {T e(back()); pop_back(); return e;}
|
//! \brief
|
||||||
inline T take_front() {T e(front()); pop_front(); return e;}
|
//! \~english Appends the given elements to the end of the array.
|
||||||
|
//! \~russian Добавляет элементы в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & append(std::initializer_list<T> init_list) {
|
||||||
|
return push_back(init_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given array `v` to the end of the array.
|
||||||
|
//! \~russian Добавляет массив `v` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.append(PIDeque<int>{4, 5});
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & append(const PIDeque<T> & v) {
|
||||||
|
return push_back(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v << 4 << 5;
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & operator <<(const T & e) {
|
||||||
|
return push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v << 4 << 5;
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & operator <<(T && e) {
|
||||||
|
return push_back(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given array `v` to the end of the array.
|
||||||
|
//! \~russian Добавляет массив `v` в конец массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v << PIDeque<int>{4, 5};
|
||||||
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a append(), \a push_back()
|
||||||
|
inline PIDeque<T> & operator <<(const PIDeque<T> & v) {
|
||||||
|
return append(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If there is free space at the beginning of the array,
|
||||||
|
//! which is most often, then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
|
//! If there is no free space at the beginning of the array
|
||||||
|
//! then all iterators and references
|
||||||
|
//! (including the past-the-begin iterator) are invalidated.
|
||||||
|
//! Otherwise only the past-the-begin iterator is invalidated.
|
||||||
|
//! \~russian Если в начале массива имеется свободное место,
|
||||||
|
//! что чаше всего, то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
|
//! Если в начале массива нет свободного места,
|
||||||
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
|
//! В противном случае, все, кроме итераторов указывающих на начало массива,
|
||||||
|
//! остаются в рабочем состоянии.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.push_front(4);
|
||||||
|
//! v.push_front(5);
|
||||||
|
//! piCout << v; // {5, 4, 1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a push_back(), \a append(), \a prepend(), \a insert()
|
||||||
|
inline PIDeque<T> & push_front(const T & e) {
|
||||||
|
insert(0, e);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\sa \a push_front()
|
||||||
|
inline PIDeque<T> & push_front(T && e) {
|
||||||
|
insert(0, std::move(e));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given array `v` to the begin of the array.
|
||||||
|
//! \~russian Добавляет массив `v` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.push_front(PIDeque<int>{4, 5});
|
||||||
|
//! piCout << v; // {4, 5, 1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a push_front()
|
||||||
|
inline PIDeque<T> & push_front(const PIDeque<T> & v) {
|
||||||
|
insert(0, v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given elements to the begin of the array.
|
||||||
|
//! \~russian Добавляет элементы в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & push_front(std::initializer_list<T> init_list) {
|
||||||
|
insert(0, init_list);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english If there is free space at the beginning of the array,
|
||||||
|
//! which is most often, then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
|
//! If there is no free space at the beginning of the array
|
||||||
|
//! then all iterators and references
|
||||||
|
//! (including the past-the-begin iterator) are invalidated.
|
||||||
|
//! Otherwise only the past-the-begin iterator is invalidated.
|
||||||
|
//! \~russian Если в начале массива имеется свободное место,
|
||||||
|
//! что чаше всего, то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
|
//! Если в начале массива нет свободного места,
|
||||||
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
|
//! В противном случае, все, кроме итераторов указывающих на начало массива,
|
||||||
|
//! остаются в рабочем состоянии.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.prepend(4);
|
||||||
|
//! v.prepend(5);
|
||||||
|
//! piCout << v; // {5, 4, 1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a push_back(), \a append(), \a prepend(), \a insert()
|
||||||
|
inline PIDeque<T> & prepend(const T & e) {
|
||||||
|
return push_front(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
|
//! \~russian Добавляет элемент `e` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\sa \a prepend()
|
||||||
|
inline PIDeque<T> & prepend(T && e) {
|
||||||
|
return push_front(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given array `v` to the begin of the array.
|
||||||
|
//! \~russian Добавляет массив `v` в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.prepend(PIDeque<int>{4, 5});
|
||||||
|
//! piCout << v; // {4, 5, 1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a prepend()
|
||||||
|
inline PIDeque<T> & prepend(const PIDeque<T> & v) {
|
||||||
|
return push_front(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given elements to the begin of the array.
|
||||||
|
//! \~russian Добавляет элементы в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIDeque<T> & prepend(std::initializer_list<T> init_list) {
|
||||||
|
return prepend(init_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \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
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.pop_back();
|
||||||
|
//! piCout << v; // {1, 2}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a pop_front(), \a take_back(), \a take_front()
|
||||||
|
inline PIDeque<T> & pop_back() {
|
||||||
|
if (pid_size == 0) return *this;
|
||||||
|
resize(pid_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
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! v.pop_front();
|
||||||
|
//! piCout << v; // {2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a pop_back(), \a take_back(), \a take_front()
|
||||||
|
inline PIDeque<T> & pop_front() {
|
||||||
|
if (pid_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
|
||||||
|
//! PIDeque<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
|
||||||
|
//! PIDeque<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
|
||||||
|
//! PIDeque<double> v{1.1, 2.5, 3.8};
|
||||||
|
//! PIDeque<int> v2 = v.toType<int>();
|
||||||
|
//! piCout << v2; // {1, 2, 3}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a map()
|
||||||
template <typename ST>
|
template <typename ST>
|
||||||
PIDeque<ST> toType() const {
|
inline PIDeque<ST> toType() const {
|
||||||
PIDeque<ST> ret(pid_size);
|
PIDeque<ST> ret(pid_size);
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
for (size_t i = 0; i < pid_size; ++i) {
|
||||||
ret[i] = ST(pid_data[i + pid_start]);
|
ret[i] = ST(pid_data[i + pid_start]);
|
||||||
@@ -818,45 +2220,167 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PIDeque<T> & forEach(std::function<void(const T & e)> f) const {
|
//! \brief
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
//! \~english Returns a new array with all elements
|
||||||
f(pid_data[i + pid_start]);
|
//! that pass the test implemented by the provided function `test`.
|
||||||
}
|
//! \~russian Возвращает новый массив со всеми элементами,
|
||||||
return *this;
|
//! прошедшими проверку, задаваемую в передаваемой функции `test`.
|
||||||
}
|
//! \~\details
|
||||||
PIDeque<T> copyForEach(std::function<T(const T & e)> f) const {
|
//! \~\code
|
||||||
PIDeque<T> ret; ret.reserve(pid_size);
|
//! PIDeque<int> v{3, 2, 5, 2, 7};
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
//! PIDeque<int> v2 = v.filter([](const int & i){return i > 2;});
|
||||||
ret << f(pid_data[i + pid_start]);
|
//! piCout << v2; // {3, 5, 7}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a map(), \a any(), \a every()
|
||||||
|
inline PIDeque<T> filter(std::function<bool(const T & e)> test) const {
|
||||||
|
PIDeque<T> ret;
|
||||||
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
|
if (test(pid_data[i])) ret << pid_data[i];
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
PIDeque<T> & forEachInplace(std::function<T(const T & e)> f) {
|
|
||||||
for (size_t i = 0; i < pid_size; ++i)
|
//! \brief
|
||||||
pid_data[i + pid_start] = f(pid_data[i + pid_start]);
|
//! \~english Execute function `void f(const T & e)` for every element in array.
|
||||||
|
//! \~russian Выполняет функцию `void f(const T & e)` для каждого элемента массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~russian Не позволяет изменять элементы массива.
|
||||||
|
//! Для редактирования элементов используйте функцию вида `void f(T & e)`.
|
||||||
|
//! \~english Does not allow changing array elements.
|
||||||
|
//! To edit elements, use the function like `void f(T & e)`
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4, 5};
|
||||||
|
//! int s = 0;
|
||||||
|
//! v.forEach([&s](const int & e){s += e;});
|
||||||
|
//! piCout << s; // 15
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a filter(), \a map(), \a reduce(), \a any(), \a every()
|
||||||
|
inline void forEach(std::function<void(const T & e)> f) const {
|
||||||
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
|
f(pid_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Execute function `void f(T & e)` for every element in array.
|
||||||
|
//! \~russian Выполняет функцию `void f(T & e)` для каждого элемента массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Allows you to change the elements of the array.
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Позволяет изменять элементы массива.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4, 5};
|
||||||
|
//! v.forEach([](int & e){e++;});
|
||||||
|
//! piCout << v; // {2, 3, 4, 5, 6}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a filter(), \a map(), \a reduce(), \a any(), \a every()
|
||||||
|
inline PIDeque<T> & forEach(std::function<void(T & e)> f) {
|
||||||
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
|
f(pid_data[i]);
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Сreates a new array populated with the results
|
||||||
|
//! of calling a provided function `ST f(const T & e)` on every element in the calling array.
|
||||||
|
//! \~russian Создаёт новый массив с результатом вызова указанной функции
|
||||||
|
//! `ST f(const T & e)` для каждого элемента массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Calls a provided function`ST f(const T & e)`
|
||||||
|
//! once for each element in an array, in order,
|
||||||
|
//! and constructs a new array from the results.
|
||||||
|
//! \~russian Метод `map` вызывает переданную функцию `ST f(const T & e)`
|
||||||
|
//! один раз для каждого элемента, в порядке их появления
|
||||||
|
//! и конструирует новый массив из результатов её вызова.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3};
|
||||||
|
//! PIStringList sl = v.map<PIString>([](const int & i){return PIString::fromNumber(i);});
|
||||||
|
//! piCout << sl; {"1", "2", "3"}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a forEach(), \a reduce()
|
||||||
template <typename ST>
|
template <typename ST>
|
||||||
PIDeque<ST> map(std::function<ST(const T & e)> f) const {
|
inline PIDeque<ST> map(std::function<ST(const T & e)> f) const {
|
||||||
PIDeque<ST> ret; ret.reserve(pid_size);
|
PIDeque<ST> ret; ret.reserve(pid_size);
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
ret << f(pid_data[i + pid_start]);
|
ret << f(pid_data[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template <typename ST>
|
|
||||||
PIDeque<ST> toType(std::function<ST(const T & e)> f) const {return map(f);}
|
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Applies the function `ST f(const T & e, const ST & acc)`
|
||||||
|
//! to each element of the array (from left to right), returns one value.
|
||||||
|
//! \~russian Применяет функцию `ST f(const T & e, const ST & acc)`
|
||||||
|
//! к каждому элементу массива (слева-направо), возвращает одно значение.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The reduce() method performs the `f` function
|
||||||
|
//! once for each element in the array.
|
||||||
|
//! If the `initial` argument is passed when calling reduce(),
|
||||||
|
//! then when the function `f` is called for the first time,
|
||||||
|
//! the value of `acc` will be assigned to `initial`.
|
||||||
|
//! If the array is empty, the value `initial` will be returned.
|
||||||
|
//! \param f is a function like `ST f(const T & e, const ST & acc)`,
|
||||||
|
//! executed for each element of the array. It takes two arguments:
|
||||||
|
//! * **e** - current element of the array
|
||||||
|
//! * **acc** - accumulator accumulating the value
|
||||||
|
//! which this function returns after visiting the next element
|
||||||
|
//!
|
||||||
|
//! \param initial _optional_ Object used as the second argument
|
||||||
|
//! when the `f` function is first called.
|
||||||
|
//! \~russian Метод reduce() выполняет функцию `f`
|
||||||
|
//! один раз для каждого элемента, присутствующего в массиве.
|
||||||
|
//! Если при вызове reduce() передан аргумент `initial`,
|
||||||
|
//! то при первом вызове функции `f` значение `acc`
|
||||||
|
//! будет равным значению `initial`.
|
||||||
|
//! Если массив пустой то будет возвращено значение `initial`.
|
||||||
|
//! \param f Функция, вида `ST f(const T & e, const ST & acc)`,
|
||||||
|
//! выполняющаяся для каждого элемента массива.
|
||||||
|
//! Она принимает два аргумента:
|
||||||
|
//! * **e** - текущий элемент массива
|
||||||
|
//! * **acc** - аккумулятор, аккумулирующий значение
|
||||||
|
//! которое возвращает эта функция после посещения очередного элемента
|
||||||
|
//!
|
||||||
|
//! \param initial _опциональный_ Объект,
|
||||||
|
//! используемый в качестве второго аргумента при первом вызове функции `f`.
|
||||||
|
//!
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4, 5};
|
||||||
|
//! int s = v.reduce<int>([](const int & e, const int & acc){return e + acc;});
|
||||||
|
//! piCout << s; // 15
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a forEach(), \a map()
|
||||||
template <typename ST>
|
template <typename ST>
|
||||||
ST reduce(std::function<ST(const T & e, const ST & acc)> f, const ST & initial = ST()) const {
|
inline ST reduce(std::function<ST(const T & e, const ST & acc)> f, const ST & initial = ST()) const {
|
||||||
ST ret(initial);
|
ST ret(initial);
|
||||||
for (size_t i = 0; i < pid_size; ++i) {
|
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||||
ret = f(pid_data[i + pid_start], ret);
|
ret = f(pid_data[i], ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PIDeque<PIDeque<T>> reshape(size_t rows, size_t cols, int order = byRow) const {
|
//! \brief
|
||||||
|
//! \~english Changes the dimension of the array, creates a two-dimensional array from a one-dimensional array.
|
||||||
|
//! \~russian Изменяет размерность массива, из одномерного массива создает двухмерный.
|
||||||
|
//! \~\details
|
||||||
|
//! \~russian
|
||||||
|
//! \param rows размер внешнего массива
|
||||||
|
//! \param cols размер внутренних массивов
|
||||||
|
//! \param order порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder
|
||||||
|
//! \~english
|
||||||
|
//! \param rows size external array
|
||||||
|
//! \param cols size internal arrays
|
||||||
|
//! \param order the order of traversing the source array is set using \a ReshapeOrder
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4};
|
||||||
|
//! PIDeque<PIDeque<int>> m1 = v.reshape(2,2);
|
||||||
|
//! piCout << m1; // {{1, 2}, {3, 4}}
|
||||||
|
//! PIDeque<PIDeque<int>> m2 = v.reshape(2,2, ReshapeByColumn);
|
||||||
|
//! piCout << m2; // {{1, 3}, {2, 4}}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a map(), \a reduce(), \a flatten()
|
||||||
|
inline PIDeque<PIDeque<T>> reshape(size_t rows, size_t cols, ReshapeOrder order = ReshapeByRow) const {
|
||||||
PIDeque<PIDeque<T>> ret;
|
PIDeque<PIDeque<T>> ret;
|
||||||
if (isEmpty()) return ret;
|
if (isEmpty()) return ret;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@@ -866,12 +2390,12 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
assert(rows*cols == pid_size);
|
assert(rows*cols == pid_size);
|
||||||
ret.resize(rows);
|
ret.resize(rows);
|
||||||
if (order == byRow) {
|
if (order == ReshapeByRow) {
|
||||||
for (size_t r = 0; r < rows; r++) {
|
for (size_t r = 0; r < rows; r++) {
|
||||||
ret[r] = PIDeque<T>(&(pid_data[r*cols]), cols);
|
ret[r] = PIDeque<T>(&(pid_data[r*cols]), cols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (order == byColumn) {
|
if (order == ReshapeByColumn) {
|
||||||
for (size_t r = 0; r < rows; r++) {
|
for (size_t r = 0; r < rows; r++) {
|
||||||
ret[r].resize(cols);
|
ret[r].resize(cols);
|
||||||
for (size_t c = 0; c < cols; c++) {
|
for (size_t c = 0; c < cols; c++) {
|
||||||
@@ -882,21 +2406,36 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Changes the dimension of the array, creates a one-dimensional array from a two-dimensional array.
|
||||||
|
//! \~russian Изменяет размерность массива, из двухмерный массива создает одномерный.
|
||||||
|
//! \~\details
|
||||||
|
//! \~russian Делает массив плоским.
|
||||||
|
//! Порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder.
|
||||||
|
//! \~english Makes the array flat.
|
||||||
|
//! Еhe order of traversing the source array is set using \a ReshapeOrder.
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4, 5, 6};
|
||||||
|
//! PIDeque<PIDeque<int>> xv = v.reshape(3,2);
|
||||||
|
//! piCout << xv; // {{1, 2}, {3, 4}, {5, 6}}
|
||||||
|
//! piCout << xv.flatten<int>(); // {1, 2, 3, 4, 5, 6}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a map(), \a reduce(), \a reshape()
|
||||||
template<typename C, typename std::enable_if<
|
template<typename C, typename std::enable_if<
|
||||||
std::is_same<T, PIDeque<C>>::value
|
std::is_same<T, PIDeque<C>>::value
|
||||||
, int>::type = 0>
|
, int>::type = 0>
|
||||||
inline PIDeque<C> reshape(int order = byRow) const {
|
inline PIDeque<C> flatten(ReshapeOrder order = ReshapeByRow) const {
|
||||||
PIDeque<C> ret;
|
PIDeque<C> ret;
|
||||||
if (isEmpty()) return ret;
|
if (isEmpty()) return ret;
|
||||||
size_t rows = size();
|
size_t rows = size();
|
||||||
size_t cols = at(0).size();
|
size_t cols = at(0).size();
|
||||||
ret.reserve(rows * cols);
|
ret.reserve(rows * cols);
|
||||||
if (order == byRow) {
|
if (order == ReshapeByRow) {
|
||||||
for (size_t r = 0; r < rows; r++) {
|
for (size_t r = 0; r < rows; r++) {
|
||||||
ret.append(at(r));
|
ret.append(at(r));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (order == byColumn) {
|
if (order == ReshapeByColumn) {
|
||||||
for (size_t c = 0; c < cols; c++) {
|
for (size_t c = 0; c < cols; c++) {
|
||||||
for (size_t r = 0; r < rows; r++) {
|
for (size_t r = 0; r < rows; r++) {
|
||||||
ret << at(r)[c];
|
ret << at(r)[c];
|
||||||
@@ -907,6 +2446,33 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Changes the dimension of the two-dimensional array.
|
||||||
|
//! \~russian Изменяет размерность двухмерного массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~russian
|
||||||
|
//! \param rows размер внешнего массива
|
||||||
|
//! \param cols размер внутренних массивов
|
||||||
|
//! \param order порядок обхода исходного массива, задаётся с помощью \a ReshapeOrder
|
||||||
|
//! \~english
|
||||||
|
//! \param rows size external array
|
||||||
|
//! \param cols size internal arrays
|
||||||
|
//! \param order the order of traversing the source array is set using \a ReshapeOrder
|
||||||
|
//! \~\code
|
||||||
|
//! PIDeque<int> v{1, 2, 3, 4, 5, 6};
|
||||||
|
//! PIDeque<PIDeque<int>> xv = v.reshape(3,2);
|
||||||
|
//! piCout << xv; // {{1, 2}, {3, 4}, {5, 6}}
|
||||||
|
//! piCout << xv.reshape<int>(2,3); // {{1, 2, 3}, {4, 5, 6}}
|
||||||
|
//! \endcode
|
||||||
|
//! \~\sa \a map(), \a reduce(), \a reshape()
|
||||||
|
template<typename C, typename std::enable_if<
|
||||||
|
std::is_same<T, PIDeque<C>>::value
|
||||||
|
, int>::type = 0>
|
||||||
|
inline PIDeque<PIDeque<C>> reshape(size_t rows, size_t cols, ReshapeOrder order = ReshapeByRow) const {
|
||||||
|
PIDeque<C> fl = flatten<C>();
|
||||||
|
return fl.reshape(rows, cols, order);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void _reset() {pid_size = pid_rsize = pid_start = 0; pid_data = 0;}
|
inline void _reset() {pid_size = pid_rsize = pid_start = 0; pid_data = 0;}
|
||||||
inline size_t asize(ssize_t s) {
|
inline size_t asize(ssize_t s) {
|
||||||
@@ -1051,6 +2617,8 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
#ifdef PIP_STD_IOSTREAM
|
#ifdef PIP_STD_IOSTREAM
|
||||||
|
//! \~english Output operator to [std::ostream](https://en.cppreference.com/w/cpp/io/basic_ostream).
|
||||||
|
//! \~russian Оператор вывода в [std::ostream](https://ru.cppreference.com/w/cpp/io/basic_ostream).
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline std::ostream & operator <<(std::ostream & s, const PIDeque<T> & v) {
|
inline std::ostream & operator <<(std::ostream & s, const PIDeque<T> & v) {
|
||||||
s << "{";
|
s << "{";
|
||||||
@@ -1063,6 +2631,10 @@ inline std::ostream & operator <<(std::ostream & s, const PIDeque<T> & v) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//! \relatesalso PICout
|
||||||
|
//! \~english Output operator to \a PICout
|
||||||
|
//! \~russian Оператор вывода в \a PICout
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline PICout operator <<(PICout s, const PIDeque<T> & v) {
|
inline PICout operator <<(PICout s, const PIDeque<T> & v) {
|
||||||
s.space();
|
s.space();
|
||||||
@@ -1077,7 +2649,10 @@ inline PICout operator <<(PICout s, const PIDeque<T> & v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void piSwap(PIDeque<T> & f, PIDeque<T> & s) {f.swap(s);}
|
template<typename T>
|
||||||
|
inline void piSwap(PIDeque<T> & f, PIDeque<T> & s) {
|
||||||
|
f.swap(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // PIDEQUE_H
|
#endif // PIDEQUE_H
|
||||||
|
|||||||
@@ -106,14 +106,14 @@ public:
|
|||||||
typedef bool (*CompareFunc)(const T & , const T & );
|
typedef bool (*CompareFunc)(const T & , const T & );
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Constructs an empty vector.
|
//! \~english Constructs an empty array.
|
||||||
//! \~russian Создает пустой массив.
|
//! \~russian Создает пустой массив.
|
||||||
inline PIVector(): piv_data(0), piv_size(0), piv_rsize(0) {
|
inline PIVector(): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Contructs vector from raw `data`.
|
//! \~english Contructs array from raw `data`.
|
||||||
//! This constructor reserve `size` and copy from `data` pointer.
|
//! This constructor reserve `size` and copy from `data` pointer.
|
||||||
//! \~russian Создает массив из указателя на данные `data` и размер `size`.
|
//! \~russian Создает массив из указателя на данные `data` и размер `size`.
|
||||||
//! То есть выделяет память для `size` элементов и копирует данные из указателя `data`.
|
//! То есть выделяет память для `size` элементов и копирует данные из указателя `data`.
|
||||||
@@ -133,7 +133,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Contructs vector from
|
//! \~english Contructs array from
|
||||||
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
//! \~russian Создает массив из
|
//! \~russian Создает массив из
|
||||||
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
@@ -149,7 +149,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Contructs vector with size `size` filled elements `e`.
|
//! \~english Contructs array with size `size` filled elements `e`.
|
||||||
//! \~russian Создает массив из `size` элементов заполненных `e`.
|
//! \~russian Создает массив из `size` элементов заполненных `e`.
|
||||||
inline PIVector(size_t size, const T & e = T()): piv_data(0), piv_size(0), piv_rsize(0) {
|
inline PIVector(size_t size, const T & e = T()): piv_data(0), piv_size(0), piv_rsize(0) {
|
||||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||||
@@ -157,7 +157,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Contructs vector with size `size` and elements created by function `f(size_t i)`.
|
//! \~english Contructs array with size `size` and elements created by function `f(size_t i)`.
|
||||||
//! \~russian Создает массив из `size` элементов созданных функцией `f(size_t i)`.
|
//! \~russian Создает массив из `size` элементов созданных функцией `f(size_t i)`.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english Can use
|
//! \~english Can use
|
||||||
@@ -226,35 +226,94 @@ public:
|
|||||||
|
|
||||||
inline iterator(): parent(0), pos(0) {}
|
inline iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline T & operator *() {return (*parent)[pos];}
|
inline T & operator *() {
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
inline T & operator ->() {return (*parent)[pos];}
|
}
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline T & operator ->() {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline iterator & operator ++() {++pos; return *this;}
|
inline iterator & operator ++() {
|
||||||
inline iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
++pos;
|
||||||
inline iterator & operator --() {--pos; return *this;}
|
return *this;
|
||||||
inline iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
}
|
||||||
|
inline iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline iterator & operator --() {
|
||||||
|
--pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline iterator & operator +=(const iterator & it) {pos += it.pos; return *this;}
|
inline iterator & operator +=(const iterator & it) {
|
||||||
inline iterator & operator +=(size_t p) {pos += p; return *this;}
|
pos += it.pos;
|
||||||
inline iterator & operator -=(const iterator & it) {pos -= it.pos; return *this;}
|
return *this;
|
||||||
inline iterator & operator -=(size_t p) {pos -= p; return *this;}
|
}
|
||||||
|
inline iterator & operator +=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator -=(const iterator & it) {
|
||||||
|
pos -= it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline iterator & operator -=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline iterator operator -(const iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline iterator operator -(const iterator & it, size_t p) {
|
||||||
friend inline iterator operator -(size_t p, const iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const iterator & it1, const iterator & it2) {return it1.pos - it2.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline iterator operator -(size_t p, const iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos - it2.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline iterator operator +(const iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline iterator operator +(const iterator & it, size_t p) {
|
||||||
friend inline iterator operator +(size_t p, const iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline iterator operator +(size_t p, const iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const iterator & it) const {
|
||||||
inline bool operator !=(const iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const iterator & it1, const iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const iterator & it1, const iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const iterator & it) const {
|
||||||
friend inline bool operator >(const iterator & it1, const iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const iterator & it1, const iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
void dump() {piCout << parent << pos;}
|
friend inline bool operator <(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const iterator & it1, const iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
@@ -272,32 +331,88 @@ public:
|
|||||||
|
|
||||||
inline const_iterator(): parent(0), pos(0) {}
|
inline const_iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline const_iterator & operator ++() {++pos; return *this;}
|
inline const_iterator & operator ++() {
|
||||||
inline const_iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
++pos;
|
||||||
inline const_iterator & operator --() {--pos; return *this;}
|
return *this;
|
||||||
inline const_iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
}
|
||||||
|
inline const_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator --() {
|
||||||
|
--pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline const_iterator & operator +=(const const_iterator & it) {pos += it.pos; return *this;}
|
inline const_iterator & operator +=(const const_iterator & it) {
|
||||||
inline const_iterator & operator +=(size_t p) {pos += p; return *this;}
|
pos += it.pos;
|
||||||
inline const_iterator & operator -=(const const_iterator & it) {pos -= it.pos; return *this;}
|
return *this;
|
||||||
inline const_iterator & operator -=(size_t p) {pos -= p; return *this;}
|
}
|
||||||
|
inline const_iterator & operator +=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator -=(const const_iterator & it) {
|
||||||
|
pos -= it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_iterator & operator -=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_iterator operator -(const const_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline const_iterator operator -(const const_iterator & it, size_t p) {
|
||||||
friend inline const_iterator operator -(size_t p, const const_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const const_iterator & it1, const const_iterator & it2) {return it1.pos - it2.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_iterator operator -(size_t p, const const_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos - it2.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_iterator operator +(const const_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline const_iterator operator +(const const_iterator & it, size_t p) {
|
||||||
friend inline const_iterator operator +(size_t p, const const_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_iterator operator +(size_t p, const const_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const const_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const const_iterator & it) const {
|
||||||
inline bool operator !=(const const_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const const_iterator & it1, const const_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const const_iterator & it1, const const_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const const_iterator & it) const {
|
||||||
friend inline bool operator >(const const_iterator & it1, const const_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const const_iterator & it1, const const_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const const_iterator & it1, const const_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class reverse_iterator {
|
class reverse_iterator {
|
||||||
@@ -315,34 +430,94 @@ public:
|
|||||||
|
|
||||||
inline reverse_iterator(): parent(0), pos(0) {}
|
inline reverse_iterator(): parent(0), pos(0) {}
|
||||||
|
|
||||||
inline T & operator *() {return (*parent)[pos];}
|
inline T & operator *() {
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
inline T & operator ->() {return (*parent)[pos];}
|
}
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline T & operator ->() {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline reverse_iterator & operator ++() {--pos; return *this;}
|
inline reverse_iterator & operator ++() {
|
||||||
inline reverse_iterator & operator ++(int) {const auto tmp = *this; --*this; return tmp;}
|
--pos;
|
||||||
inline reverse_iterator & operator --() {++pos; return *this;}
|
return *this;
|
||||||
inline reverse_iterator & operator --(int) {const auto tmp = *this; ++*this; return tmp;}
|
}
|
||||||
|
inline reverse_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator --() {
|
||||||
|
++pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline reverse_iterator & operator +=(const reverse_iterator & it) {pos -= it.pos; return *this;}
|
inline reverse_iterator & operator +=(const reverse_iterator & it) {
|
||||||
inline reverse_iterator & operator +=(size_t p) {pos -= p; return *this;}
|
pos -= it.pos;
|
||||||
inline reverse_iterator & operator -=(const reverse_iterator & it) {pos += it.pos; return *this;}
|
return *this;
|
||||||
inline reverse_iterator & operator -=(size_t p) {pos += p; return *this;}
|
}
|
||||||
|
inline reverse_iterator & operator +=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator -=(const reverse_iterator & it) {
|
||||||
|
pos += it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline reverse_iterator & operator -=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline reverse_iterator operator -(const reverse_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline reverse_iterator operator -(const reverse_iterator & it, size_t p) {
|
||||||
friend inline reverse_iterator operator -(size_t p, const reverse_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const reverse_iterator & it1, const reverse_iterator & it2) {return it2.pos - it1.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline reverse_iterator operator -(size_t p, const reverse_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it2.pos - it1.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline reverse_iterator operator +(const reverse_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline reverse_iterator operator +(const reverse_iterator & it, size_t p) {
|
||||||
friend inline reverse_iterator operator +(size_t p, const reverse_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline reverse_iterator operator +(size_t p, const reverse_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const reverse_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const reverse_iterator & it) const {
|
||||||
inline bool operator !=(const reverse_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const reverse_iterator & it) const {
|
||||||
friend inline bool operator >(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const reverse_iterator & it1, const reverse_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
|
friend inline bool operator <(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const reverse_iterator & it1, const reverse_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_reverse_iterator {
|
class const_reverse_iterator {
|
||||||
@@ -359,44 +534,101 @@ public:
|
|||||||
typedef std::random_access_iterator_tag iterator_category;
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
|
||||||
inline const_reverse_iterator(): parent(0), pos(0) {}
|
inline const_reverse_iterator(): parent(0), pos(0) {}
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {
|
||||||
inline const T & operator ->() const {return (*parent)[pos];}
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
inline const T & operator ->() const {
|
||||||
|
return (*parent)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
inline const_reverse_iterator & operator ++() {--pos; return *this;}
|
inline const_reverse_iterator & operator ++() {
|
||||||
inline const_reverse_iterator & operator ++(int) {const auto tmp = *this; --*this; return tmp;}
|
--pos;
|
||||||
inline const_reverse_iterator & operator --() {++pos; return *this;}
|
return *this;
|
||||||
inline const_reverse_iterator & operator --(int) {const auto tmp = *this; ++*this; return tmp;}
|
}
|
||||||
|
inline const_reverse_iterator & operator ++(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
--*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator --() {
|
||||||
|
++pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator --(int) {
|
||||||
|
const auto tmp = *this;
|
||||||
|
++*this;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
inline const_reverse_iterator & operator +=(const const_reverse_iterator & it) {pos -= it.pos; return *this;}
|
inline const_reverse_iterator & operator +=(const const_reverse_iterator & it) {
|
||||||
inline const_reverse_iterator & operator +=(size_t p) {pos -= p; return *this;}
|
pos -= it.pos;
|
||||||
inline const_reverse_iterator & operator -=(const const_reverse_iterator & it) {pos += it.pos; return *this;}
|
return *this;
|
||||||
inline const_reverse_iterator & operator -=(size_t p) {pos += p; return *this;}
|
}
|
||||||
|
inline const_reverse_iterator & operator +=(size_t p) {
|
||||||
|
pos -= p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator -=(const const_reverse_iterator & it) {
|
||||||
|
pos += it.pos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator & operator -=(size_t p) {
|
||||||
|
pos += p;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_reverse_iterator operator -(const const_reverse_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
friend inline const_reverse_iterator operator -(const const_reverse_iterator & it, size_t p) {
|
||||||
friend inline const_reverse_iterator operator -(size_t p, const const_reverse_iterator & it) {return it - p;}
|
auto tmp = it;
|
||||||
friend inline std::ptrdiff_t operator -(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it2.pos - it1.pos;}
|
tmp -= p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_reverse_iterator operator -(size_t p, const const_reverse_iterator & it) {
|
||||||
|
return it - p;
|
||||||
|
}
|
||||||
|
friend inline std::ptrdiff_t operator -(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it2.pos - it1.pos;
|
||||||
|
}
|
||||||
|
|
||||||
friend inline const_reverse_iterator operator +(const const_reverse_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
friend inline const_reverse_iterator operator +(const const_reverse_iterator & it, size_t p) {
|
||||||
friend inline const_reverse_iterator operator +(size_t p, const const_reverse_iterator & it) {return it + p;}
|
auto tmp = it;
|
||||||
|
tmp += p;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
friend inline const_reverse_iterator operator +(size_t p, const const_reverse_iterator & it) {
|
||||||
|
return it + p;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool operator ==(const const_reverse_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const const_reverse_iterator & it) const {
|
||||||
inline bool operator !=(const const_reverse_iterator & it) const {return (pos != it.pos);}
|
return (pos == it.pos);
|
||||||
friend inline bool operator <(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos < it2.pos;}
|
}
|
||||||
friend inline bool operator <=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos <= it2.pos;}
|
inline bool operator !=(const const_reverse_iterator & it) const {
|
||||||
friend inline bool operator >(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos > it2.pos;}
|
return (pos != it.pos);
|
||||||
friend inline bool operator >=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {return it1.pos >= it2.pos;}
|
}
|
||||||
};
|
friend inline bool operator <(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos < it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator <=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos <= it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos > it2.pos;
|
||||||
|
}
|
||||||
|
friend inline bool operator >=(const const_reverse_iterator & it1, const const_reverse_iterator & it2) {
|
||||||
|
return it1.pos >= it2.pos;
|
||||||
|
} };
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Iterator to the first element.
|
//! \~english Iterator to the first element.
|
||||||
//! \~russian Итератор на первый элемент.
|
//! \~russian Итератор на первый элемент.
|
||||||
//! \~\details 
|
//! \~\details 
|
||||||
//!
|
//!
|
||||||
//! \~english If the vector is empty, the returned iterator is equal to \a end().
|
//! \~english If the array is empty, the returned iterator is equal to \a end().
|
||||||
//! \~russian Если массив - пуст, возвращаемый итератор будет равен \a end().
|
//! \~russian Если массив - пуст, возвращаемый итератор будет равен \a end().
|
||||||
//! \~\return \ref stl_iterators
|
//! \~\return \ref stl_iterators
|
||||||
//! \~\sa \a end(), \a rbegin(), \a rend()
|
//! \~\sa \a end(), \a rbegin(), \a rend()
|
||||||
inline iterator begin() {return iterator(this, 0);}
|
inline iterator begin() {
|
||||||
|
return iterator(this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Iterator to the element following the last element.
|
//! \~english Iterator to the element following the last element.
|
||||||
@@ -409,32 +641,40 @@ public:
|
|||||||
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
||||||
//! \~\return \ref stl_iterators
|
//! \~\return \ref stl_iterators
|
||||||
//! \~\sa \a begin(), \a rbegin(), \a rend()
|
//! \~\sa \a begin(), \a rbegin(), \a rend()
|
||||||
inline iterator end() {return iterator(this, piv_size);}
|
inline iterator end() {
|
||||||
|
return iterator(this, piv_size);
|
||||||
|
}
|
||||||
|
|
||||||
inline const_iterator begin() const {return const_iterator(this, 0);}
|
inline const_iterator begin() const {
|
||||||
inline const_iterator end() const {return const_iterator(this, piv_size);}
|
return const_iterator(this, 0);
|
||||||
|
}
|
||||||
|
inline const_iterator end() const {
|
||||||
|
return const_iterator(this, piv_size);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Returns a reverse iterator to the first element of the reversed vector.
|
//! \~english Returns a reverse iterator to the first element of the reversed array.
|
||||||
//! \~russian Обратный итератор на первый элемент.
|
//! \~russian Обратный итератор на первый элемент.
|
||||||
//! \~\details 
|
//! \~\details 
|
||||||
//!
|
//!
|
||||||
//! \~english It corresponds to the last element of the non-reversed vector.
|
//! \~english It corresponds to the last element of the non-reversed array.
|
||||||
//! If the vector is empty, the returned iterator is equal to \a rend().
|
//! If the array is empty, the returned iterator is equal to \a rend().
|
||||||
//! \~russian Итератор для прохода массива в обратном порядке.
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
//! Указывает на последний элемент.
|
//! Указывает на последний элемент.
|
||||||
//! Если массив пустой, то совпадает с итератором \a rend().
|
//! Если массив пустой, то совпадает с итератором \a rend().
|
||||||
//! \~\return \ref stl_iterators
|
//! \~\return \ref stl_iterators
|
||||||
//! \~\sa \a rend(), \a begin(), \a end()
|
//! \~\sa \a rend(), \a begin(), \a end()
|
||||||
inline reverse_iterator rbegin() {return reverse_iterator(this, piv_size - 1);}
|
inline reverse_iterator rbegin() {
|
||||||
|
return reverse_iterator(this, piv_size - 1);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Returns a reverse iterator to the element
|
//! \~english Returns a reverse iterator to the element
|
||||||
//! following the last element of the reversed vector.
|
//! following the last element of the reversed array.
|
||||||
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
//! \~russian Обратный итератор на элемент, следующий за последним элементом.
|
||||||
//! \~\details 
|
//! \~\details 
|
||||||
//!
|
//!
|
||||||
//! \~english It corresponds to the element preceding the first element of the non-reversed vector.
|
//! \~english It corresponds to the element preceding the first element of the non-reversed array.
|
||||||
//! This element acts as a placeholder, attempting to access it results in undefined behavior.
|
//! This element acts as a placeholder, attempting to access it results in undefined behavior.
|
||||||
//! \~russian Итератор для прохода массива в обратном порядке.
|
//! \~russian Итератор для прохода массива в обратном порядке.
|
||||||
//! Указывает на элемент, предшествующий первому элементу.
|
//! Указывает на элемент, предшествующий первому элементу.
|
||||||
@@ -442,28 +682,40 @@ public:
|
|||||||
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
//! попытка доступа к нему приведёт к выходу за разрешенную память.
|
||||||
//! \~\return \ref stl_iterators
|
//! \~\return \ref stl_iterators
|
||||||
//! \~\sa \a rbegin(), \a begin(), \a end()
|
//! \~\sa \a rbegin(), \a begin(), \a end()
|
||||||
inline reverse_iterator rend() {return reverse_iterator(this, -1);}
|
inline reverse_iterator rend() {
|
||||||
|
return reverse_iterator(this, -1);
|
||||||
|
}
|
||||||
|
|
||||||
inline const_reverse_iterator rbegin() const {return const_reverse_iterator(this, piv_size - 1);}
|
inline const_reverse_iterator rbegin() const {
|
||||||
inline const_reverse_iterator rend() const {return const_reverse_iterator(this, -1);}
|
return const_reverse_iterator(this, piv_size - 1);
|
||||||
|
}
|
||||||
|
inline const_reverse_iterator rend() const {
|
||||||
|
return const_reverse_iterator(this, -1);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Number of elements in the container.
|
//! \~english Number of elements in the container.
|
||||||
//! \~russian Количество элементов массива.
|
//! \~russian Количество элементов массива.
|
||||||
//! \~\sa \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
//! \~\sa \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
inline size_t size() const {return piv_size;}
|
inline size_t size() const {
|
||||||
|
return piv_size;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Number of elements in the container as signed value.
|
//! \~english Number of elements in the container as signed value.
|
||||||
//! \~russian Количество элементов массива в виде знакового числа.
|
//! \~russian Количество элементов массива в виде знакового числа.
|
||||||
//! \~\sa \a size(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
//! \~\sa \a size(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
inline ssize_t size_s() const {return piv_size;}
|
inline ssize_t size_s() const {
|
||||||
|
return piv_size;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Same as \a size().
|
//! \~english Same as \a size().
|
||||||
//! \~russian Синоним \a size().
|
//! \~russian Синоним \a size().
|
||||||
//! \~\sa \a size(), \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
//! \~\sa \a size(), \a size_s(), \a capacity(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
inline size_t length() const {return piv_size;}
|
inline size_t length() const {
|
||||||
|
return piv_size;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Number of elements that the container has currently allocated space for.
|
//! \~english Number of elements that the container has currently allocated space for.
|
||||||
@@ -472,7 +724,9 @@ public:
|
|||||||
//! \~english To find out the actual number of items, use the function \a size().
|
//! \~english To find out the actual number of items, use the function \a size().
|
||||||
//! \~russian Чтобы узнать фактическое количество элементов используйте функцию \a size().
|
//! \~russian Чтобы узнать фактическое количество элементов используйте функцию \a size().
|
||||||
//! \~\sa \a reserve(), \a size(), \a size_s()
|
//! \~\sa \a reserve(), \a size(), \a size_s()
|
||||||
inline size_t capacity() const {return piv_rsize;}
|
inline size_t capacity() const {
|
||||||
|
return piv_rsize;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Checks if the container has no elements.
|
//! \~english Checks if the container has no elements.
|
||||||
@@ -481,7 +735,9 @@ public:
|
|||||||
//! \~english **true** if the container is empty, **false** otherwise
|
//! \~english **true** if the container is empty, **false** otherwise
|
||||||
//! \~russian **true** если контейнер пуст, **false** иначе.
|
//! \~russian **true** если контейнер пуст, **false** иначе.
|
||||||
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
inline bool isEmpty() const {return (piv_size == 0);}
|
inline bool isEmpty() const {
|
||||||
|
return (piv_size == 0);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Checks if the container has elements.
|
//! \~english Checks if the container has elements.
|
||||||
@@ -490,7 +746,9 @@ public:
|
|||||||
//! \~english **true** if the container is not empty, **false** otherwise
|
//! \~english **true** if the container is not empty, **false** otherwise
|
||||||
//! \~russian **true** если контейнер не пуст, **false** иначе.
|
//! \~russian **true** если контейнер не пуст, **false** иначе.
|
||||||
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
//! \~\sa \a size(), \a size_s(), \a isEmpty(), \a isNotEmpty(), \a resize(), \a reserve()
|
||||||
inline bool isNotEmpty() const {return (piv_size > 0);}
|
inline bool isNotEmpty() const {
|
||||||
|
return (piv_size > 0);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Tests whether at least one element in the array
|
//! \~english Tests whether at least one element in the array
|
||||||
@@ -561,8 +819,12 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 5, 9}
|
//! piCout << v; // {1, 2, 5, 9}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a at()
|
//! \~\sa \a at()
|
||||||
inline T & operator [](size_t index) {return piv_data[index];}
|
inline T & operator [](size_t index) {
|
||||||
inline const T & operator [](size_t index) const {return piv_data[index];}
|
return piv_data[index];
|
||||||
|
}
|
||||||
|
inline const T & operator [](size_t index) const {
|
||||||
|
return piv_data[index];
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Read only access to element by `index`.
|
//! \~english Read only access to element by `index`.
|
||||||
@@ -574,53 +836,61 @@ public:
|
|||||||
//! \~russian Индекс элемента считается от `0`.
|
//! \~russian Индекс элемента считается от `0`.
|
||||||
//! Индекс элемента должен лежать в пределах от `0` до `size()-1`.
|
//! Индекс элемента должен лежать в пределах от `0` до `size()-1`.
|
||||||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
inline const T & at(size_t index) const {return piv_data[index];}
|
inline const T & at(size_t index) const {
|
||||||
|
return piv_data[index];
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Last element.
|
//! \~english Last element.
|
||||||
//! \~russian Последний элемент массива.
|
//! \~russian Последний элемент массива.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english Returns a reference to the last item in the vector.
|
//! \~english Returns a reference to the last item in the array.
|
||||||
//! This function assumes that the vector isn't empty.
|
//! This function assumes that the array isn't empty.
|
||||||
//! Otherwise will be undefined behavior.
|
//! Otherwise will be undefined behavior.
|
||||||
//! \~russian Возвращает ссылку на последний элемент в массиве.
|
//! \~russian Возвращает ссылку на последний элемент в массиве.
|
||||||
//! Эта функция предполагает, что массив не пустой.
|
//! Эта функция предполагает, что массив не пустой.
|
||||||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
inline T & back() {return piv_data[piv_size - 1];}
|
inline T & back() {
|
||||||
inline const T & back() const {return piv_data[piv_size - 1];}
|
return piv_data[piv_size - 1];
|
||||||
|
}
|
||||||
|
inline const T & back() const {
|
||||||
|
return piv_data[piv_size - 1];
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Last element.
|
//! \~english Last element.
|
||||||
//! \~russian Первый элемент массива.
|
//! \~russian Первый элемент массива.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english Returns a reference to the last item in the vector.
|
//! \~english Returns a reference to the last item in the array.
|
||||||
//! This function assumes that the vector isn't empty.
|
//! This function assumes that the array isn't empty.
|
||||||
//! Otherwise will be undefined behavior.
|
//! Otherwise will be undefined behavior.
|
||||||
//! \~russian Возвращает ссылку на пенрвый элемент в массиве.
|
//! \~russian Возвращает ссылку на пенрвый элемент в массиве.
|
||||||
//! Эта функция предполагает, что массив не пустой.
|
//! Эта функция предполагает, что массив не пустой.
|
||||||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||||
inline T & front() {return piv_data[0];}
|
inline T & front() {
|
||||||
inline const T & front() const {return piv_data[0];}
|
return piv_data[0];
|
||||||
|
}
|
||||||
|
inline const T & front() const {
|
||||||
|
return piv_data[0];
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Compare operator with vector `t`.
|
//! \~english Compare operator with array `v`.
|
||||||
//! \~russian Оператор сравнения с массивом `t`.
|
//! \~russian Оператор сравнения с массивом `v`.
|
||||||
inline bool operator ==(const PIVector<T> & t) const {
|
inline bool operator ==(const PIVector<T> & v) const {
|
||||||
if (piv_size != t.piv_size) {
|
if (piv_size != v.piv_size) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < piv_size; ++i) {
|
for (size_t i = 0; i < piv_size; ++i) {
|
||||||
if (t[i] != piv_data[i]) {
|
if (v[i] != piv_data[i]) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Compare operator with vector `t`.
|
//! \~english Compare operator with array `v`.
|
||||||
//! \~russian Оператор сравнения с массивом `t`.
|
//! \~russian Оператор сравнения с массивом `v`.
|
||||||
inline bool operator !=(const PIVector<T> & t) const {return !(*this == t);}
|
inline bool operator !=(const PIVector<T> & v) const {
|
||||||
|
return !(*this == v);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Tests if element `e` exists in the array.
|
//! \~english Tests if element `e` exists in the array.
|
||||||
@@ -913,14 +1183,16 @@ public:
|
|||||||
//! memcpy(vec.data(1), carr, 2 * sizeof(int));
|
//! memcpy(vec.data(1), carr, 2 * sizeof(int));
|
||||||
//! piCout << v; // {2, 12, 13, 2}
|
//! piCout << v; // {2, 12, 13, 2}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
inline T * data(size_t index = 0) {return &(piv_data[index]);}
|
inline T * data(size_t index = 0) {
|
||||||
|
return &(piv_data[index]);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Read only pointer to array
|
//! \~english Read only pointer to array
|
||||||
//! \~russian Указатель на память массива только для чтения.
|
//! \~russian Указатель на память массива только для чтения.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english The pointer can be used to access and modify the items in the vector.
|
//! \~english The pointer can be used to access and modify the items in the array.
|
||||||
//! The pointer remains valid as long as the vector isn't reallocated.
|
//! The pointer remains valid as long as the array isn't reallocated.
|
||||||
//! Optional argument `index` the position in this array,
|
//! Optional argument `index` the position in this array,
|
||||||
//! where is pointer. Default: start of array.
|
//! where is pointer. Default: start of array.
|
||||||
//! \~russian Указатель можно использовать для доступа и изменения элементов в массиве.
|
//! \~russian Указатель можно использовать для доступа и изменения элементов в массиве.
|
||||||
@@ -933,7 +1205,9 @@ public:
|
|||||||
//! memcpy(a, v.data(), a.size() * sizeof(int));
|
//! memcpy(a, v.data(), a.size() * sizeof(int));
|
||||||
//! piCout << a[0] << a[1] << a[2]; // 1 3 5
|
//! piCout << a[0] << a[1] << a[2]; // 1 3 5
|
||||||
//! \endcode
|
//! \endcode
|
||||||
inline const T * data(size_t index = 0) const {return &(piv_data[index]);}
|
inline const T * data(size_t index = 0) const {
|
||||||
|
return &(piv_data[index]);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Creates sub-array of this array.
|
//! \~english Creates sub-array of this array.
|
||||||
@@ -982,8 +1256,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Assigns element 'f' to all items in the array.
|
//! \~english Assigns element 'e' to all items in the array.
|
||||||
//! \~russian Заполняет весь массив копиями элемента 'f'.
|
//! \~russian Заполняет весь массив копиями элемента 'e'.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \code
|
//! \code
|
||||||
//! PIVector<int> v{1, 3, 5};
|
//! PIVector<int> v{1, 3, 5};
|
||||||
@@ -991,11 +1265,11 @@ public:
|
|||||||
//! piCout << v; // {7, 7, 7}
|
//! piCout << v; // {7, 7, 7}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a resize()
|
//! \~\sa \a resize()
|
||||||
inline PIVector<T> & fill(const T & f = T()) {
|
inline PIVector<T> & fill(const T & e = T()) {
|
||||||
deleteT(piv_data, piv_size);
|
deleteT(piv_data, piv_size);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, piv_size)
|
PIINTROSPECTION_CONTAINER_USED(T, piv_size)
|
||||||
for (size_t i = 0; i < piv_size; ++i) {
|
for (size_t i = 0; i < piv_size; ++i) {
|
||||||
elementNew(piv_data + i, f);
|
elementNew(piv_data + i, e);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1023,12 +1297,13 @@ public:
|
|||||||
//! \~english Same as \a fill().
|
//! \~english Same as \a fill().
|
||||||
//! \~russian Тоже самое что и \a fill().
|
//! \~russian Тоже самое что и \a fill().
|
||||||
//! \~\sa \a fill(), \a resize()
|
//! \~\sa \a fill(), \a resize()
|
||||||
inline PIVector<T> & assign(const T & f = T()) {return fill(f);}
|
inline PIVector<T> & assign(const T & e = T()) {
|
||||||
|
return fill(e);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english First does `resize(new_size)` then `fill(f)`.
|
//! \~english First does `resize(new_size)` then `fill(e)`.
|
||||||
//! \~russian Сначала делает `resize(new_size)` затем `fill(f)`.
|
//! \~russian Сначала делает `resize(new_size)` затем `fill(e)`.
|
||||||
//! \~\sa \a fill(), \a resize()
|
//! \~\sa \a fill(), \a resize()
|
||||||
template<typename T1 = T, typename std::enable_if<
|
template<typename T1 = T, typename std::enable_if<
|
||||||
!std::is_trivially_copyable<T1>::value
|
!std::is_trivially_copyable<T1>::value
|
||||||
@@ -1046,18 +1321,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Sets size of the array, new elements are copied from `f`.
|
//! \~english Sets size of the array, new elements are copied from `e`.
|
||||||
//! \~russian Устанавливает размер массива, новые элементы копируются из `f`.
|
//! \~russian Устанавливает размер массива, новые элементы копируются из `e`.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If `new_size` is greater than the current \a size(),
|
//! \~english If `new_size` is greater than the current \a size(),
|
||||||
//! elements are added to the end; the new elements are initialized from `f`.
|
//! elements are added to the end; the new elements are initialized from `e`.
|
||||||
//! If `new_size` is less than the current \a size(), elements are removed from the end.
|
//! If `new_size` is less than the current \a size(), elements are removed from the end.
|
||||||
//! \~russian Если `new_size` больше чем текущий размер массива \a size(),
|
//! \~russian Если `new_size` больше чем текущий размер массива \a size(),
|
||||||
//! новые элементы добавляются в конец массива и создаются из `f`.
|
//! новые элементы добавляются в конец массива и создаются из `e`.
|
||||||
//! Если `new_size` меньше чем текущий размер массива \a size(),
|
//! Если `new_size` меньше чем текущий размер массива \a size(),
|
||||||
//! лишние элементы удаляются с конца массива.
|
//! лишние элементы удаляются с конца массива.
|
||||||
//! \~\sa \a size(), \a clear()
|
//! \~\sa \a size(), \a clear()
|
||||||
inline PIVector<T> & resize(size_t new_size, const T & f = T()) {
|
inline PIVector<T> & resize(size_t new_size, const T & e = T()) {
|
||||||
if (new_size < piv_size) {
|
if (new_size < piv_size) {
|
||||||
T * de = &(piv_data[new_size]);
|
T * de = &(piv_data[new_size]);
|
||||||
deleteT(de, piv_size - new_size);
|
deleteT(de, piv_size - new_size);
|
||||||
@@ -1068,7 +1343,7 @@ public:
|
|||||||
alloc(new_size);
|
alloc(new_size);
|
||||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os))
|
||||||
for (size_t i = os; i < new_size; ++i) {
|
for (size_t i = os; i < new_size; ++i) {
|
||||||
elementNew(piv_data + i, f);
|
elementNew(piv_data + i, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@@ -1209,6 +1484,27 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english Inserts the given elements at `index` position in the array.
|
||||||
|
//! \~russian Вставляет элементы в позицию `index` в массиве.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english The index must be greater than or equal to 0 and less than or equal to \a size().
|
||||||
|
//! Inserts the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Индекс должен быть больше или равен 0 и меньше или равен \a size().
|
||||||
|
//! Вставляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||||
|
inline PIVector<T> & insert(size_t index, std::initializer_list<T> init_list) {
|
||||||
|
ssize_t os = piv_size - index;
|
||||||
|
alloc(piv_size + init_list.size());
|
||||||
|
if (os > 0) {
|
||||||
|
memmove((void*)(&(piv_data[index + init_list.size()])), (const void*)(&(piv_data[index])), os * sizeof(T));
|
||||||
|
}
|
||||||
|
newT(piv_data + index, init_list.begin(), init_list.size());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Removes `count` elements from the middle of the array, starting at `index` position.
|
//! \~english Removes `count` elements from the middle of the array, starting at `index` position.
|
||||||
//! \~russian Удаляет элементы из массива, начиная с позиции `index`, в количестве `count`.
|
//! \~russian Удаляет элементы из массива, начиная с позиции `index`, в количестве `count`.
|
||||||
@@ -1306,7 +1602,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Reverses this array.
|
//! \~english Reverses this array.
|
||||||
//! \~russian Обращает порядок следования элементов этого массива.
|
//! \~russian Обращает порядок следования элементов этого массива.
|
||||||
@@ -1431,13 +1726,15 @@ public:
|
|||||||
//! \~russian Добавляет элемент `e` в конец массива.
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english If size() is less than capacity(), which is most often
|
//! \~english If size() is less than capacity(), which is most often
|
||||||
//! then the addition will be very fast, and does not depend on the size of the array.
|
//! then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
//! If the new size() is greater than capacity()
|
//! If the new size() is greater than capacity()
|
||||||
//! then all iterators and references
|
//! then all iterators and references
|
||||||
//! (including the past-the-end iterator) are invalidated.
|
//! (including the past-the-end iterator) are invalidated.
|
||||||
//! Otherwise only the past-the-end iterator is invalidated.
|
//! Otherwise only the past-the-end iterator is invalidated.
|
||||||
//! \~russian Если size() меньше capacity(), что чаше всего,
|
//! \~russian Если size() меньше capacity(), что чаше всего,
|
||||||
//! то добавление будет очень быстрым, и не зависит от размера массива.
|
//! то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
//! Если новый size() больше, чем capacity(),
|
//! Если новый size() больше, чем capacity(),
|
||||||
//! то все итераторы и указатели становятся нерабочими.
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
||||||
@@ -1512,14 +1809,17 @@ public:
|
|||||||
//! \~english Appends the given element `e` to the end of the array.
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
//! \~russian Добавляет элемент `e` в конец массива.
|
//! \~russian Добавляет элемент `e` в конец массива.
|
||||||
//! \~\details
|
//! \~\details
|
||||||
|
//! \~\details
|
||||||
//! \~english If size() is less than capacity(), which is most often
|
//! \~english If size() is less than capacity(), which is most often
|
||||||
//! then the addition will be very fast, and does not depend on the size of the array.
|
//! then the addition will be very fast.
|
||||||
|
//! In any case, the addition is fast and does not depend on the size of the array.
|
||||||
//! If the new size() is greater than capacity()
|
//! If the new size() is greater than capacity()
|
||||||
//! then all iterators and references
|
//! then all iterators and references
|
||||||
//! (including the past-the-end iterator) are invalidated.
|
//! (including the past-the-end iterator) are invalidated.
|
||||||
//! Otherwise only the past-the-end iterator is invalidated.
|
//! Otherwise only the past-the-end iterator is invalidated.
|
||||||
//! \~russian Если size() меньше capacity(), что чаше всего,
|
//! \~russian Если size() меньше capacity(), что чаше всего,
|
||||||
//! то добавление будет очень быстрым, и не зависит от размера массива.
|
//! то добавление будет очень быстрым.
|
||||||
|
//! В любом случае добавление быстрое и не зависит от размера массива.
|
||||||
//! Если новый size() больше, чем capacity(),
|
//! Если новый size() больше, чем capacity(),
|
||||||
//! то все итераторы и указатели становятся нерабочими.
|
//! то все итераторы и указатели становятся нерабочими.
|
||||||
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
//! В противном случае, все, кроме итераторов указывающих на конец массива,
|
||||||
@@ -1531,7 +1831,9 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a prepend(), \a push_front(), \a push_back(), \a insert()
|
//! \~\sa \a prepend(), \a push_front(), \a push_back(), \a insert()
|
||||||
inline PIVector<T> & append(const T & e) {return push_back(e);}
|
inline PIVector<T> & append(const T & e) {
|
||||||
|
return push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the end of the array.
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
@@ -1540,7 +1842,9 @@ public:
|
|||||||
//! \~english Overloaded function.
|
//! \~english Overloaded function.
|
||||||
//! \~russian Перегруженая функция.
|
//! \~russian Перегруженая функция.
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & append(T && e) {return push_back(std::move(e));}
|
inline PIVector<T> & append(T && e) {
|
||||||
|
return push_back(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given elements to the end of the array.
|
//! \~english Appends the given elements to the end of the array.
|
||||||
@@ -1553,7 +1857,9 @@ public:
|
|||||||
//! Добавляет элементы из
|
//! Добавляет элементы из
|
||||||
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & append(std::initializer_list<T> init_list) {return push_back(init_list);}
|
inline PIVector<T> & append(std::initializer_list<T> init_list) {
|
||||||
|
return push_back(init_list);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given array `v` to the end of the array.
|
//! \~english Appends the given array `v` to the end of the array.
|
||||||
@@ -1567,7 +1873,9 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & append(const PIVector<T> & v) {return push_back(v);}
|
inline PIVector<T> & append(const PIVector<T> & v) {
|
||||||
|
return push_back(v);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the end of the array.
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
@@ -1579,7 +1887,9 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & operator <<(const T & e) {return push_back(e);}
|
inline PIVector<T> & operator <<(const T & e) {
|
||||||
|
return push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the end of the array.
|
//! \~english Appends the given element `e` to the end of the array.
|
||||||
@@ -1591,7 +1901,9 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & operator <<(T && e) {return push_back(std::move(e));}
|
inline PIVector<T> & operator <<(T && e) {
|
||||||
|
return push_back(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given array `v` to the end of the array.
|
//! \~english Appends the given array `v` to the end of the array.
|
||||||
@@ -1603,7 +1915,9 @@ public:
|
|||||||
//! piCout << v; // {1, 2, 3, 4, 5}
|
//! piCout << v; // {1, 2, 3, 4, 5}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a append()
|
//! \~\sa \a append()
|
||||||
inline PIVector<T> & operator <<(const PIVector<T> & v) {return push_back(v);}
|
inline PIVector<T> & operator <<(const PIVector<T> & v) {
|
||||||
|
return push_back(v);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the begin of the array.
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
@@ -1656,6 +1970,22 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given elements to the begin of the array.
|
||||||
|
//! \~russian Добавляет элементы в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIVector<T> & push_front(std::initializer_list<T> init_list) {
|
||||||
|
insert(0, init_list);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the begin of the array.
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
//! \~russian Добавляет элемент `e` в начало массива.
|
//! \~russian Добавляет элемент `e` в начало массива.
|
||||||
@@ -1673,7 +2003,9 @@ public:
|
|||||||
//! piCout << v; // {5, 4, 1, 2, 3}
|
//! piCout << v; // {5, 4, 1, 2, 3}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a append(), \a push_back(), \a push_front(), \a insert()
|
//! \~\sa \a append(), \a push_back(), \a push_front(), \a insert()
|
||||||
inline PIVector<T> & prepend(const T & e) {return push_front(e);}
|
inline PIVector<T> & prepend(const T & e) {
|
||||||
|
return push_front(e);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given element `e` to the begin of the array.
|
//! \~english Appends the given element `e` to the begin of the array.
|
||||||
@@ -1682,7 +2014,9 @@ public:
|
|||||||
//! \~english Overloaded function.
|
//! \~english Overloaded function.
|
||||||
//! \~russian Перегруженая функция.
|
//! \~russian Перегруженая функция.
|
||||||
//! \~\sa \a prepend()
|
//! \~\sa \a prepend()
|
||||||
inline PIVector<T> & prepend(T && e) {return push_front(std::move(e));}
|
inline PIVector<T> & prepend(T && e) {
|
||||||
|
return push_front(std::move(e));
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Appends the given array `v` to the begin of the array.
|
//! \~english Appends the given array `v` to the begin of the array.
|
||||||
@@ -1696,7 +2030,24 @@ public:
|
|||||||
//! piCout << v; // {4, 5, 1, 2, 3}
|
//! piCout << v; // {4, 5, 1, 2, 3}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a prepend()
|
//! \~\sa \a prepend()
|
||||||
inline PIVector<T> & prepend(const PIVector<T> & v) {return push_front(v);}
|
inline PIVector<T> & prepend(const PIVector<T> & v) {
|
||||||
|
return push_front(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~english Appends the given elements to the begin of the array.
|
||||||
|
//! \~russian Добавляет элементы в начало массива.
|
||||||
|
//! \~\details
|
||||||
|
//! \~english Overloaded function.
|
||||||
|
//! Appends the given elements from
|
||||||
|
//! [C++11 initializer list](https://en.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~russian Перегруженая функция.
|
||||||
|
//! Добавляет элементы из
|
||||||
|
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||||
|
//! \~\sa \a append()
|
||||||
|
inline PIVector<T> & prepend(std::initializer_list<T> init_list) {
|
||||||
|
return prepend(init_list);
|
||||||
|
}
|
||||||
|
|
||||||
//! \brief
|
//! \brief
|
||||||
//! \~english Remove one element from the end of the array.
|
//! \~english Remove one element from the end of the array.
|
||||||
@@ -1781,7 +2132,7 @@ public:
|
|||||||
//! PIVector<int> v2 = v.toType<int>();
|
//! PIVector<int> v2 = v.toType<int>();
|
||||||
//! piCout << v2; // {1, 2, 3}
|
//! piCout << v2; // {1, 2, 3}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
//! \~\sa \a map()
|
||||||
template <typename ST>
|
template <typename ST>
|
||||||
inline PIVector<ST> toType() const {
|
inline PIVector<ST> toType() const {
|
||||||
PIVector<ST> ret; ret.reserve(piv_size);
|
PIVector<ST> ret; ret.reserve(piv_size);
|
||||||
@@ -1802,7 +2153,7 @@ public:
|
|||||||
//! PIVector<int> v2 = v.filter([](const int & i){return i > 2;});
|
//! PIVector<int> v2 = v.filter([](const int & i){return i > 2;});
|
||||||
//! piCout << v2; // {3, 5, 7}
|
//! piCout << v2; // {3, 5, 7}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a take_front(), \a pop_back(), \a pop_front()
|
//! \~\sa \a map(), \a any(), \a every()
|
||||||
inline PIVector<T> filter(std::function<bool(const T & e)> test) const {
|
inline PIVector<T> filter(std::function<bool(const T & e)> test) const {
|
||||||
PIVector<T> ret;
|
PIVector<T> ret;
|
||||||
for (size_t i = 0; i < piv_size; ++i) {
|
for (size_t i = 0; i < piv_size; ++i) {
|
||||||
@@ -1825,7 +2176,7 @@ public:
|
|||||||
//! v.forEach([&s](const int & e){s += e;});
|
//! v.forEach([&s](const int & e){s += e;});
|
||||||
//! piCout << s; // 15
|
//! piCout << s; // 15
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a map(), \a reduce()
|
//! \~\sa \a filter(), \a map(), \a reduce(), \a any(), \a every()
|
||||||
inline void 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) {
|
for (size_t i = 0; i < piv_size; ++i) {
|
||||||
f(piv_data[i]);
|
f(piv_data[i]);
|
||||||
@@ -1845,7 +2196,7 @@ public:
|
|||||||
//! v.forEach([](int & e){e++;});
|
//! v.forEach([](int & e){e++;});
|
||||||
//! piCout << v; // {2, 3, 4, 5, 6}
|
//! piCout << v; // {2, 3, 4, 5, 6}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a map(), \a reduce()
|
//! \~\sa \a filter(), \a map(), \a reduce(), \a any(), \a every()
|
||||||
inline PIVector<T> & forEach(std::function<void(T & e)> f) {
|
inline PIVector<T> & forEach(std::function<void(T & e)> f) {
|
||||||
for (size_t i = 0; i < piv_size; ++i) {
|
for (size_t i = 0; i < piv_size; ++i) {
|
||||||
f(piv_data[i]);
|
f(piv_data[i]);
|
||||||
@@ -1867,7 +2218,7 @@ public:
|
|||||||
//! и конструирует новый массив из результатов её вызова.
|
//! и конструирует новый массив из результатов её вызова.
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIVector<int> v{1, 2, 3};
|
//! PIVector<int> v{1, 2, 3};
|
||||||
//! PIStringList sl = v.map<PIString>([](const int & i){return PIString::fromNumber(i);});
|
//! PIVector<PIString> sl = v.map<PIString>([](const int & i){return PIString::fromNumber(i);});
|
||||||
//! piCout << sl; {"1", "2", "3"}
|
//! piCout << sl; {"1", "2", "3"}
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a forEach(), \a reduce()
|
//! \~\sa \a forEach(), \a reduce()
|
||||||
@@ -2175,6 +2526,8 @@ inline PICout operator <<(PICout s, const PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void piSwap(PIVector<T> & f, PIVector<T> & s) {f.swap(s);}
|
inline void piSwap(PIVector<T> & f, PIVector<T> & s) {
|
||||||
|
f.swap(s);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PIVECTOR_H
|
#endif // PIVECTOR_H
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ public:
|
|||||||
//! \~russian Значение для пропуска справа
|
//! \~russian Значение для пропуска справа
|
||||||
static const float ElideRight ;
|
static const float ElideRight ;
|
||||||
|
|
||||||
PIString & operator +=(const PIChar c) {push_back(c); return *this;}
|
PIString & operator +=(const PIChar & c) {PIDeque<PIChar>::push_back(c); return *this;}
|
||||||
PIString & operator +=(const char c) {push_back(PIChar(c)); return *this;}
|
PIString & operator +=(const char c) {PIDeque<PIChar>::push_back(PIChar(c)); return *this;}
|
||||||
PIString & operator +=(const char * str);
|
PIString & operator +=(const char * str);
|
||||||
PIString & operator +=(const wchar_t * str);
|
PIString & operator +=(const wchar_t * str);
|
||||||
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
|
||||||
@@ -121,7 +121,7 @@ public:
|
|||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(5, 'p'); // s = "ppppp"
|
//! PIString s(5, 'p'); // s = "ppppp"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
|
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(PIChar(c));}
|
||||||
|
|
||||||
//! \~english Contructs string as sequence of symbols "c" of buffer with length "len"
|
//! \~english Contructs string as sequence of symbols "c" of buffer with length "len"
|
||||||
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
||||||
@@ -129,7 +129,7 @@ public:
|
|||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s(5, "№"); // s = "№№№№№"
|
//! PIString s(5, "№"); // s = "№№№№№"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) push_back(c);}
|
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(c);}
|
||||||
|
|
||||||
~PIString() {}
|
~PIString() {}
|
||||||
|
|
||||||
@@ -230,8 +230,8 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const PIChar c) {*this += c; return *this;}
|
PIString & operator <<(const PIChar c) {*this += c; return *this;}
|
||||||
|
|
||||||
//! \~english Append symbol "c" at the end of string
|
//! \~english Append symbol `c` at the end of string
|
||||||
//! \~russian Добавляет в конец символ "c"
|
//! \~russian Добавляет в конец символ `c`
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIString s("stri");
|
//! PIString s("stri");
|
||||||
@@ -298,15 +298,71 @@ public:
|
|||||||
//! \endcode
|
//! \endcode
|
||||||
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
|
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the begin of string
|
||||||
|
//! \~russian Вставляет "str" в начало строки
|
||||||
|
PIString & prepend(const char * str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the begin of string
|
//! \~english Insert string "str" at the begin of string
|
||||||
//! \~russian Вставляет "str" в начало строки
|
//! \~russian Вставляет "str" в начало строки
|
||||||
PIString & prepend(const PIString & str) {insert(0, str); return *this;}
|
PIString & prepend(const PIString & str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the begin of string
|
||||||
|
//! \~russian Вставляет символ `c` в начало строки
|
||||||
|
PIString & prepend(const PIChar c) {PIDeque<PIChar>::prepend(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the begin of string
|
||||||
|
//! \~russian Вставляет символ `c` в начало строки
|
||||||
|
PIString & prepend(const char c) {PIDeque<PIChar>::prepend(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the begin of string
|
||||||
|
//! \~russian Вставляет "str" в начало строки
|
||||||
|
PIString & push_front(const char * str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the begin of string
|
||||||
|
//! \~russian Вставляет "str" в начало строки
|
||||||
|
PIString & push_front(const PIString & str) {insert(0, str); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the begin of string
|
||||||
|
//! \~russian Вставляет символ `c` в начало строки
|
||||||
|
PIString & push_front(const PIChar c) {PIDeque<PIChar>::push_front(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the begin of string
|
||||||
|
//! \~russian Вставляет символ `c` в начало строки
|
||||||
|
PIString & push_front(const char c) {PIDeque<PIChar>::push_front(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the end of string
|
||||||
|
//! \~russian Вставляет "str" в конец строки
|
||||||
|
PIString & append(const char * str) {*this += str; return *this;}
|
||||||
|
|
||||||
//! \~english Insert string "str" at the end of string
|
//! \~english Insert string "str" at the end of string
|
||||||
//! \~russian Вставляет "str" в конец строки
|
//! \~russian Вставляет "str" в конец строки
|
||||||
PIString & append(const PIString & str) {*this += str; return *this;}
|
PIString & append(const PIString & str) {*this += str; return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the end of string
|
||||||
|
//! \~russian Вставляет символ `c` в конец строки
|
||||||
|
PIString & append(const PIChar c) {PIDeque<PIChar>::append(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the end of string
|
||||||
|
//! \~russian Вставляет символ `c` в конец строки
|
||||||
|
PIString & append(const char c) {PIDeque<PIChar>::append(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the end of string
|
||||||
|
//! \~russian Вставляет "str" в конец строки
|
||||||
|
PIString & push_back(const char * str) {*this += str; return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert string "str" at the end of string
|
||||||
|
//! \~russian Вставляет "str" в конец строки
|
||||||
|
PIString & push_back(const PIString & str) {*this += str; return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the end of string
|
||||||
|
//! \~russian Вставляет символ `c` в конец строки
|
||||||
|
PIString & push_back(const PIChar c) {PIDeque<PIChar>::push_back(c); return *this;}
|
||||||
|
|
||||||
|
//! \~english Insert symbol `c` at the end of string
|
||||||
|
//! \~russian Вставляет символ `c` в конец строки
|
||||||
|
PIString & push_back(const char c) {PIDeque<PIChar>::push_back(PIChar(c)); return *this;}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns part of string from symbol at index "start" and maximum length "len"
|
//! \~english Returns part of string from symbol at index "start" and maximum length "len"
|
||||||
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len"
|
//! \~russian Возвращает подстроку от символа "start" и максимальной длиной "len"
|
||||||
@@ -600,7 +656,7 @@ public:
|
|||||||
//! piCout << s; // s = "9876543210"
|
//! piCout << s; // s = "9876543210"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a reversed()
|
//! \~\sa \a reversed()
|
||||||
PIString & reverse() {PIString str(*this); clear(); piForeachCR (PIChar c, str) push_back(c); return *this;}
|
PIString & reverse() {PIDeque<PIChar>::reverse(); return *this;}
|
||||||
|
|
||||||
//! \~english Reverse copy of this string
|
//! \~english Reverse copy of this string
|
||||||
//! \~russian Разворачивает копию этой строки
|
//! \~russian Разворачивает копию этой строки
|
||||||
@@ -611,7 +667,7 @@ public:
|
|||||||
//! piCout << s; // s = "0123456789"
|
//! piCout << s; // s = "0123456789"
|
||||||
//! \endcode
|
//! \endcode
|
||||||
//! \~\sa \a reverse()
|
//! \~\sa \a reverse()
|
||||||
PIString reversed() const {PIString str(*this); str.reverse(); return str;}
|
PIString reversed() const {PIString ret(*this); return ret.reverse();}
|
||||||
|
|
||||||
//! \~english Fit string to maximum size "size" by inserting ".." at position "pos" and return this string
|
//! \~english Fit string to maximum size "size" by inserting ".." at position "pos" and return this string
|
||||||
//! \~russian Уменьшает строку до размера "size", вставляя ".." в положение "pos" и возвращает эту строку
|
//! \~russian Уменьшает строку до размера "size", вставляя ".." в положение "pos" и возвращает эту строку
|
||||||
|
|||||||
@@ -662,10 +662,9 @@ int main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
auto it = qt_filters.makeIterator();
|
auto it = qt_filters.makeIterator();
|
||||||
while (it.next())
|
while (it.next())
|
||||||
it.valueRef().forEachInplace([](PIString i)->PIString{
|
it.valueRef().forEach([](PIString & i){
|
||||||
if (!i.startsWith("*")) i.prepend("*");
|
if (!i.startsWith("*")) i.prepend("*");
|
||||||
if (!i.endsWith("*")) i.append("*");
|
if (!i.endsWith("*")) i.append("*");
|
||||||
return i;
|
|
||||||
});
|
});
|
||||||
//PICout(PICoutManipulators::DefaultControls) << qt_filters;
|
//PICout(PICoutManipulators::DefaultControls) << qt_filters;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user