[libc++] Add an assertion in the subrange constructors with a size hint
authorLouis Dionne <ldionne.2@gmail.com>
Fri, 27 Aug 2021 16:04:58 +0000 (12:04 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Fri, 3 Sep 2021 20:04:02 +0000 (16:04 -0400)
commitfd66b44ec19e76c111c8a37a42dcb4b44a96bfd6
treec45dcfa78ce7609019155e5e76a14a7ab3678fe3
parent79f8b5f0d00fd10fee8aee3c3c58e17a8fea8946
[libc++] Add an assertion in the subrange constructors with a size hint

Those constructors are very easy to misuse -- one could easily think that
the size passed to the constructor is the size of the range to exhibit
from the subrange. Instead, it's a size hint and it's UB to get it wrong.
Hence, when it's cheap to compute the real size of the range, it's cheap
to make sure that the user didn't get it wrong.

Differential Revision: https://reviews.llvm.org/D108827
libcxx/include/__ranges/subrange.h
libcxx/test/std/ranges/range.utility/range.subrange/primitives.pass.cpp
libcxx/test/std/ranges/range.utility/range.subrange/types.h