Skip to content

Instantly share code, notes, and snippets.

@mochow13
Created September 12, 2018 08:17
Show Gist options
  • Save mochow13/9374e624eafd4b034ae8ff1f8a88227a to your computer and use it in GitHub Desktop.
Save mochow13/9374e624eafd4b034ae8ff1f8a88227a to your computer and use it in GitHub Desktop.
std::string mirror_ends(const std::string& in)
{
// mismatch takes two ranges as input, (first1,last1,first2,last2)
// if last2 is not given, it considers first2+(last1-first1) as last2
return std::string(in.begin(), std::mismatch(in.begin(), in.end(), in.rbegin()).first);
}
int main()
{
std::cout << mirror_ends("abXYZba") << '\n'
<< mirror_ends("abca") << '\n'
<< mirror_ends("aba") << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment