Last active
August 29, 2015 14:01
-
-
Save termoose/bc0e09988720befc05d9 to your computer and use it in GitHub Desktop.
This file contains 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 T> using Index = typename T::iterator::difference_type; | |
template<typename T> | |
std::pair<typename T::iterator::difference_type, T> prefix_match(T a, T b) | |
{ | |
auto mismatch = std::mismatch(a.cbegin(), a.cend(), b.cbegin()); | |
auto index = std::distance(a.cbegin(), mismatch.first); | |
return std::make_pair(index, T(a.cbegin(), mismatch.first)); | |
} | |
template<typename T> | |
std::pair<Index<T>, T> prefix_match(std::vector<T> list) | |
{ | |
return std::accumulate(list.cbegin(), list.cend(), | |
std::make_pair(Index<T>(0), *list.cbegin()), | |
[](std::pair<Index<T>, T> a, T b) | |
{ | |
return prefix_match(a.second, b); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment