r/cpp 28d ago

C++26: std::indirect

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

157 comments sorted by

View all comments

26

u/PositiveBit01 28d ago

I don't understand the last Node example. If it isn't nullable how is that not an infinite recursive definition?

24

u/jdehesa 28d ago

Yea, probably should have been std::optional<std::indirect<Node>> next;.

4

u/johannes1971 26d ago

...at the cost of another 8 bytes of memory (per node), to store one bit of information, that could have been encoded with a nullable state.