Skip to content

Instantly share code, notes, and snippets.

@qrealka
Created June 23, 2018 21:50
Show Gist options
  • Save qrealka/b1d113d7a76b6a39688f905078745b5e to your computer and use it in GitHub Desktop.
Save qrealka/b1d113d7a76b6a39688f905078745b5e to your computer and use it in GitHub Desktop.
template <class I, // I models ForwardIterator
class P, // P is binary predicate (value_type(I), value_type(I)) -> bool
class O> // O is a function (I, I) -> void
auto split(I begin, I end, P predicate, O subsequnce) -> O {
while(begin != end) {
auto split_pos = std::adjacent_find(begin, end, predicate);
if (split_pos != end) ++split_pos;
subsequnce(begin, split_pos);
begin = split_pos;
}
return subsequnce;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment