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); +}