Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active December 23, 2016 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/2fcff638061a979fa8f936eab0504a81 to your computer and use it in GitHub Desktop.
Save deque-blog/2fcff638061a979fa8f936eab0504a81 to your computer and use it in GitHub Desktop.
template<typename ForwardIterator>
void stable_sort_forward(ForwardIterator first, ForwardIterator last)
{
using Range = std::pair<ForwardIterator, ForwardIterator>;
using Counter = binary_counter<merger<ForwardIterator>, Range>;
Counter c { merger<ForwardIterator>{}, { last, last } };
accumulate_iter(first, last, &c,
[](auto c, auto it) {
c->add({it, std::next(it)});
return c;
})->reduce();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment