Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion algorithms_task_5/student/include/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
* @return gathered range
*/
template <typename BiIt, typename UnaryPredicate>
std::pair<BiIt, BiIt> gather(BiIt begin, BiIt end, BiIt position, UnaryPredicate predicate);
std::pair<BiIt, BiIt> gather(BiIt begin, BiIt end, BiIt position, UnaryPredicate predicate) {
auto invertedPredicate =
[&predicate](typename std::iterator_traits<BiIt>::value_type val) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't copy, use reference

return !predicate(val);
};

auto partitionStart = std::partition(begin, position, invertedPredicate);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable_partition?

auto partitionEnd = std::partition(position, end, predicate);
return std::make_pair(partitionStart, partitionEnd);
}