Determine if a std::string has all of the same character I'm working on an algorithm to determine if a std::string has all of the same character. Here is what I have:

bool string_has_all_of_the_same_chars(const std::string&amp; s) {
    return std::all_of(s.begin(), s.end(), [&amp;s](char ch) { return ch == s[0]; });
}


Are there any improvements that can be made to this? I am guaranteed by another function that s is not empty.
You could simply use find_first_not_of 

bool string_has_all_of_the_same_chars(const std::string&amp; s) {
    return s.find_first_not_of(s[0]) == std::string::npos;
}


Update:

This works only, when the string is not empty. A complete version would also test empty 

bool string_has_all_of_the_same_chars(const std::string&amp; s) {
    return s.empty() || s.find_first_not_of(s[0]) == std::string::npos;
}


Instead of s[0], one could also use s.front() or *s.begin().