C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Add `.at()` for `view_interface` (also along with `mdspan`)?

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Thu, 16 Nov 2023 13:49:02 -0500
On Wed, Nov 15, 2023 at 10:54 PM Hewill Kang <hewillk_at_[hidden]> wrote:

>
>> In the proposed wording, `ranges::distance` should be `ranges::size`.
>> (They do the same physical thing in this case, but the latter better
>> reflects your intent.)
>
>
> I personally prefer `ranges::distance`, which avoids the implicit
> conversion (i.e. difference type) before comparing with an index value, but
> `ranges::size` definitely sounds reasonable, and perhaps this should be
> decided by the LWG. I'll add a discussion for this.
>

Ah, I'd missed the fact that `distance` returns a signed number (which
matches what `operator[]` and `at()` take), whereas `size` returns an
unsigned number.
But then perhaps this is the perfect place to use `std::ranges::ssize`?
Anyway, the reason for choosing `distance` wasn't obvious, so adding
discussion is good.

–Arthur

>

Received on 2023-11-16 18:49:15