C++ Logo

std-proposals

Advanced search

Re: std::size_t-specializations of std::integral_constant

From: kang hewill <hewillk_at_[hidden]>
Date: Sun, 29 Aug 2021 10:55:30 +0800
>
> Though to be fair, writing a tuple-like type which can be used in
> structured binding does require using that *specific* template, so it
> wouldn't be off-base to make an alias for it.
>

When I was writing the generic library, I found that I used a lot of traits
about counting and calculating size inside the library, and they all
inherited integral_constant<size_t, N>. Aliasing them as size_constant does
save a lot of typing.

As you said, this may not be necessary, but since C++23 introduces 0z, I am
just curious whether it is possible to introduce size_constant in C++23. :)
In short, thank you for your detailed explanation!

Hewill

Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> 於
2021年8月29日 週日 上午3:19寫道:

> On Sat, Aug 28, 2021 at 2:19 PM kang hewill via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Hi C++ expert,
> >
> > I have been wondering why we have std::index_sequence but not
> std::size_constant, that is:
> >
> > template<std::size_t N>
> > using size_constant = std::integral_constant<std::size_t, N>;
> >
> > Since std::integral_constant<std::size_t, N> is widely used in the
> standard library, such as tuple_size and variant_size need to inherit it,
> so I think it is appropriate to add an alias to it in the standard, which
> can reduce a lot of typing and improve some readability, just like we
> aliased bool_constant<b> to integral_constant<bool, b>.
>
> I wouldn't call it "widely used". It's only used in the two places
> that you mentioned: things relating to `tuple_size` and
> `variant_size`. Even its use in the exposition-only `pair-like`
> concept is just about using `tuple_size`.
>
> By contrast, `bool_constant` (and its attendant `true_type` and
> `false_type` meta-values) get used quite frequently.
>
> Though to be fair, writing a tuple-like type which can be used in
> structured binding does require using that *specific* template, so it
> wouldn't be off-base to make an alias for it.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2021-08-28 21:55:44