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

-7

u/NilacTheGrim 6d 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.

12

u/yeetoteey 6d 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.

3

u/Ameisen vemips, avr, rendering, systems 5d ago

I want to be able to specify size_type. I have plenty of cases in codebases where size actually matters where uint32_t or even uint16_t would suffice.

Hell, in this case why is it still std::size_t? Fit it to N.

4

u/usefulcat 5d ago

I want to be able to specify size_type.

Same here. That's why I use boost::container::small_vector, it supports that.

3

u/Ameisen vemips, avr, rendering, systems 5d ago

I just hate to bring in boost to do everything. I already have a custom vector as my allocator supports realloc, but for things like this I would just rather not have to reinvent the entire wheel just to change size_type for every collection.

1

u/NilacTheGrim 2d ago

True. I can imagine using this in some situation where you cannot allocate but need to be able to do stuff with a buffer. Like in a signal handler, for example.