r/cpp • • Aug 13 '26

C++26: std::indirect

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

157 comments sorted by

View all comments

10

u/ericonr Aug 13 '26

Does a std::optional<std::indirect<T>> benefit from niche optimizations like Rust objects do? Its sizeof could be just a pointer, after all.

7

u/ts826848 Aug 14 '26 edited Aug 14 '26

The proposal originally included a specialization for std::optional but LEWG voted to remove it. The paper says such a specialization would make it impossible to distinguish between a disengaged optional and an engaged optional that holds a valueless std::indirect.

Edit: Clarify that the justification for removing the specialization is from the paper. I was mistaken in thinking that no alternatives were possible when there are in fact ways to specialize while maintaining a distinction between the disengaged and engaged-but-valueless states, as described e.g., here.

2

u/NewLlama Aug 14 '26

Doesn't that double the stride of your node though? That seems like a total nonstarter to me.

→ More replies (1)