Skip to content

Commit

Permalink
iterate_while support for filter_adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle committed Jul 27, 2023
1 parent 2e6300a commit 9901983
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions include/flux/op/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,31 @@ class filter_adaptor : public inline_sequence_base<filter_adaptor<Base, Pred>>
return flux::last(self.base_);
}

static constexpr auto for_each_while(self_t& self, auto&& func) -> cursor_t<Base>
static constexpr auto iterate_while(self_t& self, cursor_t<Base> from,
auto&& func) -> cursor_t<Base>
{
return flux::for_each_while(self.base_, [&](auto&& elem) {
return flux::iterate_while(self.base_, std::move(from), [&](auto&& elem) {
if (std::invoke(self.pred_, elem)) {
return std::invoke(func, FLUX_FWD(elem));
} else {
return true;
}
});
}

static constexpr auto iterate_while(self_t& self, cursor_t<Base> from,
cursor_t<Base> to, auto&& func)
-> cursor_t<Base>
{
return flux::iterate_while(self.base_, std::move(from), std::move(to),
[&](auto&& elem) {
if (std::invoke(self.pred_, elem)) {
return std::invoke(func, FLUX_FWD(elem));
} else {
return true;
}
});
}
};
};

Expand Down

0 comments on commit 9901983

Please sign in to comment.