A Constant Range of Modifiable Elements
Explore a special use case of std::span.
Kilian Henneberger reminded me of a special use case of std::span
, i.e., a constant range of modifiable elements.
For simplicity, I name a std::vector
and a std::span
a range. A std::vector
, like an std::string
models a modifiable range of modifiable elements: std::vector<T>
. When you declare this std::vector
as const
, the range models a constant range of constant objects: const std::vector<T>
. You cannot model a constant range of modifiable elements. Here comes std::span
into play. A std::span
models a constant range of modifiable objects: std::span<T>
.
The following table emphasizes the variations of (constant/modifiable) ranges and (constant/modifiable) elements.
Get hands-on with 1400+ tech skills courses.