C++ Logo

std-proposals

Advanced search

Re: std::span

From: Mario Charest <stayprivate_at_[hidden]>
Date: Tue, 14 Apr 2020 22:16:58 -0400
span cannot, in all cases, validate the index of operator[] at compile
time. Compare to [], for most containers, that's one reason why at()
exists, to generated an exception at run time. The CppCoreGuidelines (
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#slcon3-avoid-bounds-errors)
recommends using it to avoid bound errors. There std::string_view::at()
so why not for span ?


On Tue, Apr 14, 2020 at 10:02 PM Vishal Oza via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I believe the issue is the at() function has exception handling for out of
> bound errors. std::span checks bounds at compile time so the error handling
> is redundant. There is an inefficiency to have out of bounds exception
> handling even if you never use it. Zero work is always faster then work
> that is never used.
>
> On Tue, Apr 14, 2020 at 8:52 PM Mario Charest via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>> Hello,
>>
>> What is the rational for std::span not having an at() fonction, like most
>> other contiguous container.
>>
>> Regards,
>>
>> - Mario
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-04-14 21:20:09