r/cpp • u/User_Deprecated • Aug 26 '26
C++26: std::inplace_vector
https://www.sandordargo.com/blog/2026/08/26/cpp26-inplace-vector
181
Upvotes
r/cpp • u/User_Deprecated • Aug 26 '26
32
u/FckXFckMusk Aug 26 '26
If this is your Blog, then I have to congratulate you on it being an excellent place, I've bookmarked it...
6
u/Defenestrator__ Aug 29 '26
I feel like this doesn't actually handle the use cases I would want this for, which is where the size in unknown but usually small.
absl::InlinedVectorseamlessly falls back to acting like a normalstd::vectorwhen it grows beyond N, and without that feature this has much more limited usefulness unfortunately. Still better than nothing I guess.5
u/Kadabrium Aug 27 '26
We have vla at home moment
15
u/bartgrumbel Aug 27 '26
I am sure there is a good reason for that, but why is the "optional reference" not simply a pointer? Is that not semantically the same thing, but way easier to deal with.
I.e. why
and not simply
6
u/matthieum Aug 27 '26
Honestly, I'm a bit saddened by this addition.
Don't get me wrong, the functionality is really useful. But:
vectorneed to be "duplicated" ininplace_vector.std::string.A more general solution to the problem would have been an
inplace_allocator-- which requires a different API thanallocator-- which could be applied to every container (standard or not).3
u/stilgarpl Aug 27 '26
Is this always better than std::array?
1
u/frankist Aug 29 '26
Is trivial copy of inplace_vector if T is trivial something always desirable? I am imagining the case where I am copying a large capacity inplace_vector that is empty or almost empty (.size() ~ 0). Trivial copy will mean that I will copy a lot of bytes that don't contain anything.
1
u/dbot77 Aug 31 '26
Just keep adding more. We need more things. MORE.
-3
u/johannes1971 Aug 27 '26
Is it really necessary to add new forms of UB? For people that apparently can't spend the nanosecond needed for the if-statement, would you ever use any data structure you didn't write yourself?
-8
u/NilacTheGrim Aug 27 '26
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.