Skip to content

Instantly share code, notes, and snippets.

@Morwenn
Created May 31, 2019 15:12
Show Gist options
  • Save Morwenn/b1d7583d0d52e58bdab8ace7969da15a to your computer and use it in GitHub Desktop.
Save Morwenn/b1d7583d0d52e58bdab8ace7969da15a to your computer and use it in GitHub Desktop.
Try to take advantage of the stable nature of insertion sort
template<typename BidirectionalIterator, typename Compare, typename Projection>
auto insertion_sort(BidirectionalIterator first, BidirectionalIterator last,
stable_compare<Compare, Projection> compare, utility::identity)
-> void
{
auto projection = compare.projection();
cppsort::detail::insertion_sort(
first, last, compare.compare(),
[projection](auto&& value) mutable -> decltype(auto) {
return projection(std::forward<decltype(value)>(value).get());
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment