constexpr bool is_control_or_space(const char c) noexcept { return (unsigned char)c <= ' '; } std::string_view trim_classic(std::string_view input) noexcept { while (!input.empty() && is_control_or_space(input.front())) { input.remove_prefix(1); } while (!input.empty() && is_control_or_space(input.back())) { input.remove_suffix(1); } return input; } std::string_view trim_ranges(std::string_view s) { auto view = s | std::views::drop_while(is_control_or_space) | std::views::reverse | std::views...| godbolt.org
Good engineers seek software code that is 'simple' in the sense that we can read and understand it quickly. But they they also look for highly performant code. For the last 20 years, we have been offering programmers the possibility to replace conventional for loops with a more functional approach. To illustrate, suppose that you … Continue reading std::ranges may not deliver the performance that you expect| Daniel Lemire's blog