inplace_vector(from_range_t, R&& rg)Section: 23.2.4 [sequence.reqmts], 23.3.16.2 [inplace.vector.cons] Status: New Submitter: Hewill Kang Opened: 2025-10-01 Last modified: 2025-10-04
Priority: Not Prioritized
View other active issues in [sequence.reqmts].
View all other issues in [sequence.reqmts].
View all issues with New status.
Discussion:
Consider:
std::array<int, 42> a; std::inplace_vector<int, 5> v(std::from_range, a);
The above throws std::bad_alloc at runtime because the size of array is larger than
capacity of inplace_vector. However, we should reject it at compile time since the
array size is a constant expression.
<simd>,
it's worth applying that here as well. Compile-time errors are better than runtime ones.
Proposed resolution:
This wording is relative to N5014.
Modify 23.2.4 [sequence.reqmts] as indicated:
a.assign_range(rg)-60- Result:
-61- Mandates:voidassignable_from<T&, ranges::range_reference_t<R>>is modeled. Forinplace_vector, ifranges::size(rg)is a constant expression thenranges::size(rg)≤a.max_size().
Modify 23.3.16.2 [inplace.vector.cons] as indicated:
template<container-compatible-range<T> R> constexpr inplace_vector(from_range_t, R&& rg);-?- Mandates: If
-9- Effects: Constructs anranges::size(rg)is a constant expression thenranges::size(rg)≤N.inplace_vectorwith the elements of the rangerg. -10- Complexity: Linear inranges::distance(rg).