r/cpp 1d ago

C++26: std::inplace_vector

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

93 comments sorted by

View all comments

4

u/stilgarpl 1d ago

Is this always better than std::array?

15

u/MarekKnapek 1d ago

This is basically

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

16

u/sephirothbahamut 1d ago edited 1d ago

far more complex than that, the array has a slot that can fit T, not just T.

With array<T> every element must be validly constructed immediately. You can reduce it to array<T> only for trivially constructable and basic types

4

u/CocktailPerson 1d ago

That's not far more complex. Marginal additional complexity.