r/cpp • • Aug 13 '26

C++26: std::indirect

https://www.sandordargo.com/blog/2026/08/12/cpp26-indirect
164 Upvotes

157 comments sorted by

View all comments

Show parent comment

-1

u/NilacTheGrim Aug 14 '26

optional<indirect<T>> for nullable.

Yes and now you wasted ~7 bytes of class space -- when the very motivation for this indirect wrapper is to save space.

Would have been less broken if they just modeled its inherent optionality, rather than swept it under the rug leading to UB "surprises".

8

u/smdowney WG21, Text/Unicode SG, optional<T&> Aug 14 '26

The motivation was not to save space, though? Or at least that's not at all my motivation for approving or using it. Breaking the structural restriction on recursive values while communicating the intent of the underlying T* is where I use it.

-5

u/NilacTheGrim Aug 14 '26

The motivation was not to save space, though?

Of course it is. Aside from pimpl paradigm.. Why else would you anybody even really bother to use this thing unless it is to save space in a class's inherent sizeof()?

5

u/wyrn Aug 14 '26

Why do you ever use unique_ptr (without custom deleter)?

3

u/elperroborrachotoo Aug 14 '26

but it could be optimized with a partial template specialization (I think).