move std function

This commit is contained in:
2026-03-20 16:31:30 +03:00
parent 4537e40832
commit 96c22e1184
28 changed files with 145 additions and 131 deletions

View File

@@ -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;