Skip to content

Commit

Permalink
Merge pull request #181 from tcbrindle/pr/improve_for_each_while
Browse files Browse the repository at this point in the history
Specialise for_each_while for multipass + bounded sequences
  • Loading branch information
tcbrindle authored Mar 14, 2024
2 parents bf3540b + 6679696 commit 67cd4d8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions include/flux/op/for_each_while.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ struct for_each_while_fn {
if constexpr (requires { traits_t<Seq>::for_each_while(seq, std::move(pred)); }) {
return traits_t<Seq>::for_each_while(seq, std::move(pred));
} else {
auto cur = first(seq);
while (!is_last(seq, cur)) {
if (!std::invoke(pred, read_at(seq, cur))) { break; }
inc(seq, cur);
if constexpr (multipass_sequence<Seq> && bounded_sequence<Seq>) {
auto cur = first(seq);
auto end = last(seq);
while (cur != end) {
if (!std::invoke(pred, read_at(seq, cur))) { break; }
inc(seq, cur);
}
return cur;
} else {
auto cur = first(seq);
while (!is_last(seq, cur)) {
if (!std::invoke(pred, read_at(seq, cur))) { break; }
inc(seq, cur);
}
return cur;
}
return cur;
}
}
};
Expand Down

0 comments on commit 67cd4d8

Please sign in to comment.