C++ Logo

std-proposals

Advanced search

function at() for span<> that throws exception on out-of-range, like vector and array ::at()

From: Roman Babinicz <rb_at_[hidden]>
Date: Thu, 28 Nov 2019 12:37:05 +0100
Could we add operators at() to span<> container?

  value_type & at(size_type n);
  const value_type & at(size_type n) const;

they would have same behaviour as in vector, array - that is throws an
exception if n is outside of size of the container.

1) can we have that?

2) if yes, then should I write a proposal paper or how else to help in this?
Can it make it to C++20?

Imo it is a notable defect that span can not be a drop in replacement
for code taking a (reference to) array/vector that is using at().

3)
By the way, in case of span that has specific size (not dynamic_extent)
we could perhaps have a static assert and the function might be constexpr.

Received on 2019-11-28 05:39:29