From 65ea783d79c4ae46e2f62c92ca40a78d616fa204 Mon Sep 17 00:00:00 2001 From: Iulia Corici Date: Tue, 21 Feb 2023 16:37:33 +0200 Subject: [PATCH] [Iulia Corici] algorithms_task_5 --- algorithms_task_5/student/include/impl.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/algorithms_task_5/student/include/impl.h b/algorithms_task_5/student/include/impl.h index 150d7e72..36cb65df 100644 --- a/algorithms_task_5/student/include/impl.h +++ b/algorithms_task_5/student/include/impl.h @@ -10,4 +10,13 @@ * @return gathered range */ template -std::pair gather(BiIt begin, BiIt end, BiIt position, UnaryPredicate predicate); +std::pair gather(BiIt begin, BiIt end, BiIt position, UnaryPredicate predicate) { + auto invertedPredicate = + [&predicate](typename std::iterator_traits::value_type val) { + return !predicate(val); + }; + + auto partitionStart = std::partition(begin, position, invertedPredicate); + auto partitionEnd = std::partition(position, end, predicate); + return std::make_pair(partitionStart, partitionEnd); +}