std::span
std::span
is a wrapper for build-in arrays. Build-in arrays have their own syntax and semantics. They can’t be directly assigned one another, can’t pass to or return from a function.
std::span
provides range abstraction and class semantics to them, so they’ll behave just like any other std container. This especially useful when we need to pass a build-in array to a function.
Instead of:
void processBuffer(const std::uint8_t *data, const std::size_t size) { |
we can write:
void processBuffer(const std::span<std::uint8_t> buffer) { |
std::span
is C++20 addition but there exist backports even for C++98!
More on (in lexicographical order):