by jeffbee · 6y ago · 0 comments
Plugged it into compiler explorer and clang 10 does unroll the std::all_of version, doing four chars at a time.
The best of both worlds would be having the compiler transform the canonical std:: version into the fast one under the covers, but that's far from universal with current compiler tech and languages.
If anyone is interested, here is simpler version:
bool is_ascii_branchy(const std::string_view v) {
return std::all_of(v.begin(), v.end(), [](auto i) {
return uint8_t(i) < 128;});
} bool is_ascii_branchy(std::string_view v) {
for (auto c : v) if (uint8_t(c) < 128) return false;
return true;
}