r/cpp 6d ago

C++26: std::inplace_vector

https://www.sandordargo.com/blog/2026/08/26/cpp26-inplace-vector
175 Upvotes

121 comments sorted by

View all comments

4

u/stilgarpl 6d ago

Is this always better than std::array?

19

u/MarekKnapek 6d ago

This is basically

struct inplace_vector<T, capacity>
{
    size_t len;
    std::array<T, capacity> arr;
}

3

u/stilgarpl 5d ago

No, it's not. In your code it will always construct all T members of arr. Article states that inplace_vector will only have the elements needed and they don't have to be default constructible. That's a huge difference.

3

u/BenFrantzDale 5d ago

Plus this is a `std::ranges::sized_range` with dynamic size, which `std::array` is not.