move std function
This commit is contained in:
@@ -184,7 +184,7 @@ public:
|
||||
//! \endcode
|
||||
inline PIDeque(size_t piv_size, std::function<T(size_t i)> f) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
expand(piv_size, f);
|
||||
expand(piv_size, std::move(f));
|
||||
}
|
||||
|
||||
//! \~english Move constructor.
|
||||
@@ -729,7 +729,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a indexWhere()
|
||||
inline const T & atWhere(std::function<bool(const T & e)> test, ssize_t start = 0, const T & def = T()) const {
|
||||
const ssize_t i = indexWhere(test, start);
|
||||
const ssize_t i = indexWhere(std::move(test), start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -743,7 +743,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a lastIndexWhere()
|
||||
inline const T & lastAtWhere(std::function<bool(const T & e)> test, ssize_t start = -1, const T & def = T()) const {
|
||||
const ssize_t i = lastIndexWhere(test, start);
|
||||
const ssize_t i = lastIndexWhere(std::move(test), start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -1265,7 +1265,7 @@ public:
|
||||
deleteT(pid_data + pid_start + new_size, pid_size - new_size);
|
||||
pid_size = new_size;
|
||||
} else if (new_size > pid_size) {
|
||||
expand(new_size, f);
|
||||
expand(new_size, std::move(f));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1328,15 +1328,15 @@ public:
|
||||
if (index < pid_size - 1) {
|
||||
const size_t os = pid_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + 1),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, e);
|
||||
@@ -1358,15 +1358,15 @@ public:
|
||||
if (index < pid_size - 1) {
|
||||
const size_t os = pid_size - index - 1;
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + 1),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + 1),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, std::move(e));
|
||||
@@ -1393,15 +1393,15 @@ public:
|
||||
alloc_forward(pid_size + v.pid_size);
|
||||
if (os > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + v.pid_size),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + v.pid_size, -v.pid_size);
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + v.pid_size),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + v.pid_size),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, v.pid_data + v.pid_start, v.pid_size);
|
||||
@@ -1426,15 +1426,15 @@ public:
|
||||
alloc_forward(pid_size + init_list.size());
|
||||
if (os > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index + init_list.size()),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + init_list.size(), -init_list.size());
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + init_list.size()),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + init_list.size()),
|
||||
index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, init_list.begin(), init_list.size());
|
||||
@@ -1462,13 +1462,13 @@ public:
|
||||
deleteT(pid_data + pid_start + index, count);
|
||||
if (os <= index) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
} else {
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + count),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
}
|
||||
pid_start += count;
|
||||
}
|
||||
@@ -1540,7 +1540,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a sort()
|
||||
inline PIDeque<T> & sort(std::function<bool(const T & a, const T & b)> comp) {
|
||||
std::stable_sort(begin(), end(), comp);
|
||||
std::stable_sort(begin(), end(), std::move(comp));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1654,7 +1654,13 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIDeque<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||
ssize_t j = indexWhere(test);
|
||||
ssize_t j = -1;
|
||||
for (size_t i = pid_start; i < pid_start + pid_size; ++i) {
|
||||
if (test(pid_data[i])) {
|
||||
j = ssize_t(i) - pid_start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < pid_size; ++i) {
|
||||
if (!test(pid_data[i + pid_start])) {
|
||||
@@ -2545,21 +2551,21 @@ public:
|
||||
if (index + count > pid_size) count = pid_size - index;
|
||||
ret.alloc_forward(count);
|
||||
memcpy(reinterpret_cast<void *>(ret.pid_data + ret.pid_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
count * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index),
|
||||
count * sizeof(T));
|
||||
|
||||
const size_t os = pid_size - index - count;
|
||||
if (os <= index) {
|
||||
if (os > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + index),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start + index + count),
|
||||
os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
if (index > 0) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + pid_start + count),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
index * sizeof(T));
|
||||
}
|
||||
pid_start += count;
|
||||
}
|
||||
@@ -2646,8 +2652,8 @@ private:
|
||||
size_t ns = (pid_rsize - pid_size) / 2;
|
||||
if (pid_start != ns) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + ns),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
pid_start = ns;
|
||||
}
|
||||
}
|
||||
@@ -2656,8 +2662,8 @@ private:
|
||||
const size_t ns = (pid_rsize - pid_size) / 2;
|
||||
if (pid_start != ns) {
|
||||
memmove(reinterpret_cast<void *>(pid_data + ns),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
pid_start = ns;
|
||||
}
|
||||
}
|
||||
@@ -2694,8 +2700,8 @@ private:
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as - pid_rsize))
|
||||
if (pid_rsize > 0 && pid_data) {
|
||||
memcpy(reinterpret_cast<void *>(tmp_data + new_start),
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
reinterpret_cast<const void *>(pid_data + pid_start),
|
||||
pid_size * sizeof(T));
|
||||
dealloc();
|
||||
}
|
||||
pid_data = tmp_data;
|
||||
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
//! \endcode
|
||||
inline PIVector(size_t size, std::function<T(size_t i)> f) {
|
||||
PIINTROSPECTION_CONTAINER_NEW(T, sizeof(T))
|
||||
expand(size, f);
|
||||
expand(size, std::move(f));
|
||||
}
|
||||
|
||||
//! \~english Move constructor.
|
||||
@@ -725,7 +725,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a indexWhere()
|
||||
inline const T & atWhere(std::function<bool(const T & e)> test, ssize_t start = 0, const T & def = T()) const {
|
||||
const ssize_t i = indexWhere(test, start);
|
||||
const ssize_t i = indexWhere(std::move(test), start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -739,7 +739,7 @@ public:
|
||||
//! заданному в передаваемой функции `test`, или `def` если такого элемента нет.
|
||||
//! \~\sa \a lastIndexWhere()
|
||||
inline const T & lastAtWhere(std::function<bool(const T & e)> test, ssize_t start = -1, const T & def = T()) const {
|
||||
const ssize_t i = lastIndexWhere(test, start);
|
||||
const ssize_t i = lastIndexWhere(std::move(test), start);
|
||||
if (i < 0)
|
||||
return def;
|
||||
else
|
||||
@@ -1267,7 +1267,7 @@ public:
|
||||
deleteT(piv_data + new_size, piv_size - new_size);
|
||||
piv_size = new_size;
|
||||
} else if (new_size > piv_size) {
|
||||
expand(new_size, f);
|
||||
expand(new_size, std::move(f));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1486,7 +1486,7 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a sort()
|
||||
inline PIVector<T> & sort(std::function<bool(const T & a, const T & b)> comp) {
|
||||
std::stable_sort(begin(), end(), comp);
|
||||
std::stable_sort(begin(), end(), std::move(comp));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1599,7 +1599,13 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIVector<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||
ssize_t j = indexWhere(test);
|
||||
ssize_t j = -1;
|
||||
for (size_t i = 0; i < piv_size; ++i) {
|
||||
if (test(piv_data[i])) {
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < piv_size; ++i) {
|
||||
if (!test(piv_data[i])) {
|
||||
|
||||
@@ -1070,7 +1070,7 @@ public:
|
||||
//! \~english Counts elements in the flat vector that pass the `test`.
|
||||
//! \~russian Подсчитывает элементы в плоском векторе, проходящие `test`.
|
||||
//! \~\sa PIVector::entries(std::function)
|
||||
inline int entries(std::function<bool(const T & e)> test) const { return mat.entries(test); }
|
||||
inline int entries(std::function<bool(const T & e)> test) const { return mat.entries(std::move(test)); }
|
||||
|
||||
|
||||
//! \~english Returns the first index (row, col) of `e` in the 2D array.
|
||||
@@ -1086,7 +1086,7 @@ public:
|
||||
//! \~russian Возвращает первый индекс (строка, столбец) в двумерном массиве, проходящий `test`.
|
||||
//! \~\sa PIVector::indexWhere()
|
||||
inline Index indexWhere(std::function<bool(const T & e)> test, ssize_t start = 0) const {
|
||||
ssize_t flat = mat.indexWhere(test, start);
|
||||
ssize_t flat = mat.indexWhere(std::move(test), start);
|
||||
if (flat < 0 || cols_ == 0) return Index{-1, -1};
|
||||
return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
|
||||
}
|
||||
@@ -1104,7 +1104,7 @@ public:
|
||||
//! \~russian Возвращает последний индекс (строка, столбец) в двумерном массиве, проходящий `test`.
|
||||
//! \~\sa PIVector::lastIndexWhere()
|
||||
inline Index lastIndexWhere(std::function<bool(const T & e)> test, ssize_t start = -1) const {
|
||||
ssize_t flat = mat.lastIndexWhere(test, start);
|
||||
ssize_t flat = mat.lastIndexWhere(std::move(test), start);
|
||||
if (flat < 0 || cols_ == 0) return Index{-1, -1};
|
||||
return Index{flat / static_cast<ssize_t>(cols_), flat % static_cast<ssize_t>(cols_)};
|
||||
}
|
||||
@@ -1113,12 +1113,12 @@ public:
|
||||
//! \~english Tests if any element in the flat vector passes the `test`.
|
||||
//! \~russian Проверяет, проходит ли какой-либо элемент в плоском векторе `test`.
|
||||
//! \~\sa PIVector::any()
|
||||
inline bool any(std::function<bool(const T & e)> test) const { return mat.any(test); }
|
||||
inline bool any(std::function<bool(const T & e)> test) const { return mat.any(std::move(test)); }
|
||||
|
||||
//! \~english Tests if all elements in the flat vector pass the `test`.
|
||||
//! \~russian Проверяет, проходят ли все элементы в плоском векторе `test`.
|
||||
//! \~\sa PIVector::every()
|
||||
inline bool every(std::function<bool(const T & e)> test) const { return mat.every(test); }
|
||||
inline bool every(std::function<bool(const T & e)> test) const { return mat.every(std::move(test)); }
|
||||
|
||||
//! \~english Fills the entire 2D array with copies of `e`.
|
||||
//! \~russian Заполняет весь двумерный массив копиями `e`.
|
||||
@@ -1132,7 +1132,7 @@ public:
|
||||
//! \~russian Заполняет весь двумерный массив, используя функцию-генератор `f` на основе плоского индекса.
|
||||
//! \~\sa PIVector::fill(std::function)
|
||||
inline PIVector2D<T> & fill(std::function<T(size_t i)> f) {
|
||||
mat.fill(f);
|
||||
mat.fill(std::move(f));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1228,7 +1228,7 @@ public:
|
||||
//! \~\sa PIVector::map()
|
||||
template<typename ST>
|
||||
inline PIVector2D<ST> map(std::function<ST(const T & e)> f) const {
|
||||
return PIVector2D<ST>(rows_, cols_, mat.template map<ST>(f));
|
||||
return PIVector2D<ST>(rows_, cols_, mat.template map<ST>(std::move(f)));
|
||||
}
|
||||
|
||||
//! \~english Applies a function (with row and col indices) to each element and returns a new 2D array.
|
||||
@@ -1250,23 +1250,26 @@ public:
|
||||
//! \~russian Применяет функцию к каждой строке (с возможностью изменения).
|
||||
//! \~\sa forEachRow() const, PIVector::forEach()
|
||||
inline PIVector2D<T> & forEachRow(std::function<void(Row)> f) {
|
||||
for (size_t r = 0; r < rows_; ++r)
|
||||
for (size_t r = 0; r < rows_; ++r) {
|
||||
f(row(r));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Applies a function to each row (read-only).
|
||||
//! \~russian Применяет функцию к каждой строке (только чтение).
|
||||
inline void forEachRow(std::function<void(RowConst)> f) const {
|
||||
for (size_t r = 0; r < rows_; ++r)
|
||||
for (size_t r = 0; r < rows_; ++r) {
|
||||
f(row(r));
|
||||
}
|
||||
}
|
||||
|
||||
//! \~english Applies a function to each column (modifiable).
|
||||
//! \~russian Применяет функцию к каждому столбцу (с возможностью изменения).
|
||||
inline PIVector2D<T> & forEachColumn(std::function<void(Col)> f) {
|
||||
for (size_t c = 0; c < cols_; ++c)
|
||||
for (size_t c = 0; c < cols_; ++c) {
|
||||
f(col(c));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1274,8 +1277,9 @@ public:
|
||||
//! \~russian Применяет функцию к каждому столбцу (только чтение).
|
||||
//! \param f Function taking a \a ColConst.
|
||||
inline void forEachColumn(std::function<void(ColConst)> f) const {
|
||||
for (size_t c = 0; c < cols_; ++c)
|
||||
for (size_t c = 0; c < cols_; ++c) {
|
||||
f(col(c));
|
||||
}
|
||||
}
|
||||
|
||||
//! \~english Accumulates a value across all elements.
|
||||
@@ -1283,7 +1287,7 @@ public:
|
||||
//! \~\sa PIVector::reduce()
|
||||
template<typename ST>
|
||||
inline ST reduce(std::function<ST(const T & e, const ST & acc)> f, const ST & initial = ST()) const {
|
||||
return mat.template reduce<ST>(f, initial);
|
||||
return mat.template reduce<ST>(std::move(f), initial);
|
||||
}
|
||||
|
||||
//! \~english Accumulates a value across all elements with indices.
|
||||
|
||||
Reference in New Issue
Block a user