C++ Logo

std-proposals

Advanced search

Re: [span] Value of dynamic_extent

From: Bjorn Reese <breese_at_[hidden]>
Date: Tue, 2 Jul 2019 10:59:48 +0200
On 7/1/19 11:47 PM, Jorg Brown wrote:
> A vector can be empty; a string can be empty; a string_view can be
> empty; even a std::array can be empty. So why block a std::span from
> being empty, just because its extent isn't dynamic? I think this would
> end up blocking some compile-time programming cases.

A span with dynamic extent can be empty.

> Speaking of which, it's annoying that this doesn't currently work, due
> to data()'s implemenetation within std::array:
>
> constexpr const std::array<int, 0> ar0{};
> constexpr auto spanned_empty_array = std::span<const int, 0>{ar0};
>
> See https://godbolt.org/z/L4-9r8

It does not seem to work for begin/end (or cbegin/cend) either when
N = 0.

Furthermore, we cannot have zero-sized C arrays.

That sort of argues in favor of using zero as the value for dynamic
extent.

Received on 2019-07-02 04:01:43