When working with C++20 views, creating functions that encapsulate complex view compositions might be tempting.
However, that will very likely lead to unnecessary data copies. Instead, consider compositing views as inline constexpr variables.
Compiler Explorer link: https://compiler-explorer.com/z/vG4hhe77h
@simontoth O have recently enabled C++20 on an embedded code add, but haven't tried ranges and views yet.
How well do they perform on short sequences? Would code size increase compared to hand-coded loops?
And... do they work with fixed-size containers without heap allocations?
@codewiz The answer is: it depends. They mostly optimize out, but a couple of design choices can block certain optimizations.
There are 3rd party implementations that might be better.
@simontoth Hi Simon, read your blog post recently. Do you mean functions that do one or some of the range operations, and return std::string's, or functions that return view adapters?
@reed I meant wrapping this functionality into a trim function.