C++ Logo

std-discussion

Advanced search

Re: Opt-In Compile Time Bounds Checking

From: Bjorn Reese <breese_at_[hidden]>
Date: Sun, 30 Jul 2023 15:55:54 +0200
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.

Received on 2023-07-30 13:55:56