From 4144ab422eb89431f0c9ffaed8e1e4b47d062043 Mon Sep 17 00:00:00 2001 From: robtor Date: Tue, 5 Dec 2023 10:54:45 +0100 Subject: [PATCH] Revert "Remove unnecessary copy" This reverts commit e732d062b6efc6bf5d6ffccab3b4261ae34eaf57. --- task2/include/quicksort_mt.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/task2/include/quicksort_mt.h b/task2/include/quicksort_mt.h index 506f654..6d57e78 100644 --- a/task2/include/quicksort_mt.h +++ b/task2/include/quicksort_mt.h @@ -20,11 +20,13 @@ public: private: auto parition(std::span &data) -> std::pair, std::span> { - auto pivot = data.begin(); - std::advance(pivot, std::distance(data.begin(), data.end()) / 2); + std::vector 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(data.begin(), lefti), std::span(lefti, data.end())}; }