r/cpp 6d ago

C++26: std::inplace_vector

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

121 comments sorted by

View all comments

-4

u/johannes1971 5d ago

unchecked_push_back

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?

12

u/mighty_Ingvar 5d ago

I don't think it's to skip the check, it's for situations where you can be sure that max size has not been reached.

0

u/simonask_ 5d ago

We just know from experience that while you may be sure right now, such an invariant is really difficult to maintain over the course of a codebase’s lifetime. The next person, the reviewer, and yourself in 3 months will have to figure out if it holds, and there’s no way to write tests for it, because it’s UB.

Meanwhile, compilers are able to optimize out the check in exactly all the cases that are also easy to verify for humans. It’s just … unnecessary.

6

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

Meanwhile, compilers are able to optimize out the check in exactly all the cases that are also easy to verify for humans.

Except that many compilers are awful at that... probably due to assuming potential side effects or aliasing changing the size when a human knows that that won't happen.