3 ms·
Exactly that, I was surprised to see that looong for loop definition (I'm not using C++ at all) and wanted to see if there's anything else to simplify. First I
by galkk 6y ago
Exactly that, I was surprised to see that looong for loop definition (I'm not using C++ at all) and wanted to see if there's anything else to simplify. First I found for_each then all_of
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;});
}
- im3w1l 6y agoSo I guess this would be the best way to write it if you have a set of long strings most of which are non-ascii, and most such strings having a high proportion of non-ascii? Since then early exit will really help.
- jonstewart 6y agoSTL is great! How’s the performance, though, compared with TFA’s optimistic and hybrid versions?
- cornstalks 6y agoAnd for a fair comparison, here's an imperative loop that's way cleaner than what TFA used: bool is_ascii_branchy(std::string_view v) { for (auto c : v) if (uint8_t(c) < 128) return false; return true; }