C++ Logo


Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 28 Nov 2019 14:32:55 +0200
On Thu, 28 Nov 2019 at 13:37, Roman Babinicz via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> 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.

I predict this to be an uphill battle. Some audiences think that at()
should have never been
in vector, and adding it to array was a mistake, and that that mistake
shouldn't propagate
any further. I would guess that some such audiences are co-authors of span.

Personally, I think they're wrong, but I'm just giving you a heads-up
that this is not going to be
a trivial sale.

Received on 2019-11-28 06:35:28