std::mismatch

cppreference.com

Example

mirror_ends: (str: std::string) -> std::string = {
    return std::string(str.begin(),
                       std::mismatch(str.begin(), str.end(), str.rbegin()).first);
}

main: () = {
    std::cout << mirror_ends("abXYZba") << '\n'
              << mirror_ends("abca") << '\n'
              << mirror_ends("aba") << '\n';
}

Output

ab
a
aba

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.