r/cpp • • Aug 26 '26

C++26: std::inplace_vector

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

121 comments sorted by

View all comments

Show parent comment

5

u/serviscope_minor Aug 28 '26

>Is that not semantically the same thing, but way easier to deal with.

T* is a superset of std::optional<T&>. With T*, you can:

- delete

- delete[]

- Do arithmetic

- Dereference

- Test for null

With optional<T&>, you can:

- dereference

- test for null

That's basically the difference. It's a pointer, but with some of the invalid operations prevented by a very thing wrapper class.