Edit: this overload has been removed from the standard now, it seems.
From cppreference:
constexpr reference operator[](index_type idx) const; constexpr reference operator()(index_type idx) const;
Returns a reference to the
idx
-th element of the sequence. The behavior is undefined ifidx
is out of range (i.e., if it is less than zero or greater than or equal tosize()
).
It makes sense to overload operator[]
for indexing, as a span represents an object that can refer to a contiguous sequence of objects, but why is operator()
, the function call operator, also overloaded for the same purpose? I don't believe there's anything similar to this in the standard library.