Last active
December 23, 2016 15:31
-
-
Save deque-blog/e4eee1a658c1a24c5d03b133ec1b35d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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