C++ Logo

std-discussion

Advanced search

Re: Possible std::ranges::subrange defect?

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 17 Sep 2021 19:57:59 -0400
On Fri, Sep 17, 2021 at 7:21 PM Keenan Horrigan via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi, this is my first time really using a mailing list so apologies if I do anything wrong.
>
> I've been looking at std::ranges::subrange, and I think the "pair-like" concept used for converting to a pair-like type might be slightly broken? It requires std::tuple_size<T> to be derived from std::integral_constant<std::size_t, 2>, but in the specification for structured binding, as far as I can tell, it only requires `std::tuple_size<T>::value` to be a "well-formed integral constant expression", with no requirement for being related to std::integral_constant. Is it intentional that this "pair-like" concept is stricter than the requirements for structured binding?

[tuple.helper]/1 specifically states:

> All specializations of tuple_­size meet the Cpp17UnaryTypeTrait requirements ([meta.rqmts]) with a base characteristic of integral_­constant<size_­t, N> for some N.

As such, the requirements from structured binding are technically too
loose. It's not really a defect, since doing the minimum required by
structured binding would break the [tuple.helper]/1 requirement, so
it'd still be UB.

This is similar to how range-based `for` doesn't verify that the
returns of `begin/end` are iterators; it simply specifies the specific
things it will do with them.

Received on 2021-09-17 18:58:14