C++ Logo

std-discussion

Advanced search

Re: Opt-In Compile Time Bounds Checking

From: Levo DeLellis <levo.delellis_at_[hidden]>
Date: Sun, 30 Jul 2023 19:14:22 -0500
My thought was if you want all access to be guaranteed you'd use this
so having a get and an operator could cause accidental misuse such as
passing something into a template that only knows about operators
The two types is because one is would insist the length is known at
compile time and the other would insist on checking before accessing
the elements for cases when you can not know (eg reading a file)

On Sun, Jul 30, 2023 at 8:55 AM Bjorn Reese via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> On 7/28/23 04:03, Levo DeLellis via Std-Discussion wrote:
>
> > Here's a basic proposal attached, it's a small step towards memory
> > safety. Here I talk about opt-ing into a container that has bounds
> > checking at compile time. If there's any interest in having this in the
> > standard I'd be happy to write more about this and additional proposals
> > going toward memory safety
>
> Rather than defining two new span types, can this be done by adding
> a new getter to std::span that is only defined for static extent?
>
> For example by adding this member function to std::span
>
> template <size_type Position>
> constexpr reference get() const;
>
> Usage
>
> std::span<int,4> view{data};
> auto unsafe = view[2];
> auto safe = view.get<2>();
>
> PS: The std-proposals list is intended new proposals.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2023-07-31 00:15:02