C++ Logo


Advanced search

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

From: Nevin Liber <nevin_at_[hidden]>
Date: Sat, 30 Nov 2019 14:00:18 -0600
On Sat, Nov 30, 2019 at 1:21 PM Lyberta via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Anyway. My fundamental opinion is that operator[] should do bounds
> checking while unsafe_at() should not because it is clearly named unsafe.

Should all functions which have preconditions on calling them be named
unsafe_***? I would not want to call unsafe_dereference(ptr) instead of
*ptr each and every time I needed to dereference it (for example). I'm
generally against verbosity for common cases.

IMO, at() was a mistake, as the number of people who call it in the name of
"defensive programming" far outweighs the few that call it to sanitize

However, that ship sailed over two decades ago.

IMO, at() should be added to span for the sake of consistency with other

It may be a battle because some folks (not I) view span as the time to
rethink the interface.

As someone who has already fought multiple battles for span, it would take
a lot to goad me into presenting such a paper. I would, however, be likely
to support such a paper should it be presented to the committee.

IMO, it is way too late to try and get this added to C++20.
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden] <nevin_at_[hidden]>>

Received on 2019-11-30 14:03:18