C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] std::span<T> should be size_type NOT index_type.
From: Arthur O'Dwyer (arthur.j.odwyer_at_[hidden])
Date: 2019-05-13 10:06:00


sotrdg sotrdg writes:
> Please change it to size_type just like other containers!!!! I hate the
name index_type.

What other STL types have an `index_type`? (None AFAICT.)

What other STL types have a `size_type`? (Containers, allocators,
std::string, std::array, and std::string_view, AFAICT.)

The fact that `std::string_view` — also "not a container" — has `size_type`
and not `index_type` is compelling to me, in the absence of any other data
points.

I speculate that what happened here may have been the result of several
overlapping compromises related to the "signed size_type" controversy. That
is, span may have started out with a signed `size_type` alias, and then
people objected to that, so it was changed to a signed `index_type` alias
leaving room for an unsigned `size_type` to be added later, and then people
still objected to that, so it was changed to an unsigned `index_type`; but
it has not yet completed the circle back to the traditional unsigned
`size_type`.
I see that P0122R0
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0122r0.pdf>
("array_view") had both unsigned size_type and strangely-typed index_type,
but by R1 ("span") it had evolved to a plain old signed index_type and no
size_type at all.

*I suggest that someone write a paper renaming index_type to size_type.*
I'm cc'ing the author of P1024R3
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1024r3.pdf> (which
last touched std::span AFAIK) and the authors of P0122R7
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0122r7.pdf> (which
introduced the std::span with a signed index_type and no size_type) in case
they have additional information.

–Arthur

On Sun, May 12, 2019 at 6:15 PM Lyberta via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Timur Doumler via Std-Proposals:
> > std::span is not a container.
> >
> > Cheers,
> > Timur
>
> But not having size_type break templates that don't take ownership the
> the container and would otherwise be happy with std::span. I think
> having size_type vs index_type duality does nothing good.
>
> If we want people to take containers then add Container concept to the
> standard library.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups