Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The reason for std::span having both elementtype and valuetype is to provide additional flexibility in dealing with const and volatile types.

The elementtype of a std::span represents the type of the elements that the span covers, regardless of whether they are const or volatile. The elementtype can be used to define function templates that work with any type of span, regardless of whether it covers a const or non-const type.

The value_type of a std::span, on the other hand, represents the type of the elements that the span covers with any const and volatile qualifiers stripped. This is useful when working with algorithms that require a non-const type.

Having both elementtype and valuetype allows for greater precision in specifying the types used with std::span, and makes it easier to write generic algorithms that work with different const and volatile qualifiers.