Title
Improve inplace_vector(from_range_t, R&& rg)
Status
new
Section
[sequence.reqmts][inplace.vector.cons]
Submitter
Hewill Kang

Created on 2025-10-01.00:00:00 last changed 1 week ago

Messages

Date: 2025-10-04.10:32:40

Proposed resolution:

This wording is relative to N5014.

  1. Modify [sequence.reqmts] as indicated:

    a.assign_range(rg)
    

    -60- Result: void

    -61- Mandates: assignable_from<T&, ranges::range_reference_t<R>> is modeled. For `inplace_vector`, if `ranges::size(rg)` is a constant expression then `ranges::size(rg)` ≤ `a.max_size()`.

  2. Modify [inplace.vector.cons] as indicated:

    template<container-compatible-range<T> R>
      constexpr inplace_vector(from_range_t, R&& rg);
    

    -?- Mandates: If `ranges::size(rg)` is a constant expression then `ranges::size(rg)` ≤ `N`.

    -9- Effects: Constructs an `inplace_vector` with the elements of the range `rg`.

    -10- Complexity: Linear in `ranges::distance(rg)`.

Date: 2025-10-01.00:00:00

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.

Given that we do a lot of compile-time size checking in <simd>, it's worth applying that here as well. Compile-time errors are better than runtime ones.

History
Date User Action Args
2025-10-04 10:32:40adminsetmessages: + msg15110
2025-10-01 00:00:00admincreate