hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.4K
active users

Šimon Tóth

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: compiler-explorer.com/z/vG4hhe

@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.