Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active December 23, 2016 15:31
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/e4eee1a658c1a24c5d03b133ec1b35d8 to your computer and use it in GitHub Desktop.
Save deque-blog/e4eee1a658c1a24c5d03b133ec1b35d8 to your computer and use it in GitHub Desktop.
template<typename Iterator>
struct merger
{
using Value = typename std::iterator_traits<Iterator>::value_type;
using SortedRange = std::pair<Iterator, Iterator>;
SortedRange operator()(SortedRange const &lhs, SortedRange const &rhs) const {
assert(lhs.second == rhs.first);
std::vector<Value> tmp(lhs.first, lhs.second); //Copy the left range
std::merge(
std::begin(tmp), std::end(tmp), // Left container copy (source)
rhs.first, rhs.second, // Right container (source)
lhs.first); // Left container (destination)
return SortedRange(lhs.first, rhs.second);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment