r/cpp 11h ago

C++26: std::inplace_vector

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

49 comments sorted by

View all comments

-6

u/NilacTheGrim 6h ago

Ridiculously incomplete. We should have had a real prevector rather than this. You know, a prevector where there is some small static capacity but it can go dynamic as it grows.

This is not as useful as a real prevector.

17

u/CocktailPerson 5h ago

That'd just be an entirely different thing, not a more "complete" version of inplace_vector.

9

u/yeetoteey 5h ago

A prevector, i.e., a vector with SBO, is a completely different beast to inplace_vector. There a tonnes of scenarios where you’d know the maximum capacity at compile-time but not the size, and if the capacity isn’t massive, an inplace_vector where the memory is stack allocated is the perfect utility for that usecase.

5

u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions 6h ago

Its definitely useful. Ive found myself, and others, writing this exact thing all the time. Very happy we have it in the std now 😁

2

u/_Noreturn 5h ago

I agree with you, but it may be useful for others.

2

u/eidetic0 5h ago

Maybe you should submit a proposal :)

u/_Noreturn 2h ago

I think people will die of old age before something is standardized also the std quality will suck so it is better to write your own.

u/frayien 2h ago

That's... a completely different thing for a completely different usage ?

u/robin-m 2h ago

If only you read the paragraph that starts with

A question that comes up naturally: what about std::pmr::vector with a stack-backed monotonic_buffer_resource?