C++ Logo


Advanced search

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

From: Lyberta <lyberta_at_[hidden]>
Date: Sat, 30 Nov 2019 16:54:00 +0000
John McFarlane via Std-Proposals:
> Sanitizing user input sounds like something that is best served by explicit
> logic. I certainly don't think that UI is any concern of containers.

Explicit logic such as

if (i >= std::size(whatever))
 throw std::out_of_range{"Invalid index."};

How is that better than calling at()?

And without it developers will have write their own version of std::at()
anyway. I have my own versions of std::insert() and std::emplace()
already. By users I meant users of the library.

Received on 2019-11-30 10:57:19