This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4396. Improve 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.

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.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 23.2.4 [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 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 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).