Revert "Remove unnecessary copy"

This reverts commit e732d062b6.
This commit is contained in:
Robin Dietzel 2023-12-05 10:54:45 +01:00
parent e732d062b6
commit 4144ab422e

View File

@ -20,11 +20,13 @@ public:
private:
auto parition(std::span<T> &data) -> std::pair<std::span<T>, std::span<T>> {
auto pivot = data.begin();
std::advance(pivot, std::distance(data.begin(), data.end()) / 2);
std::vector<T> buf(data);
auto lefti = data.begin();
auto righti = data.end();
auto pivot = buf.begin();
std::advance(pivot, std::distance(buf.begin(), buf.end()) / 2);
auto lefti = buf.begin();
auto righti = buf.end();
while (1) {
for (; cmp(*lefti, *pivot); lefti++);
@ -37,6 +39,7 @@ private:
std::swap(lefti, righti);
}
std::move(buf.begin(), buf.end(), data.begin());
return {std::span<T>(data.begin(), lefti), std::span<T>(lefti, data.end())};
}