Edit
Here a take at @Deduplicators suggestion, I didnt see that std::mismatch returns a pair of iterators, so it is really nice and doesnt even require reverse iterators
bool oneAway(const string& s1, const string& s2)
{
if (s2.size() > s1.size()) {
return oneAway(s2, s1);
}
// From here s1.size() >= s2.size()
if (s1.size() - s2.size() > 1) {
return false;
}
auto res = std::mismatch(s2.begin(), s2.end(), s1.begin());
if (res.first== s2.end()) {
return true;
}
res = std::mismatch(res.first, s2.end(), ++res.second);
if (res.first== s2.end()) {
return true;
}
return false;
}