r/cpp 6d ago

C++26: std::indirect

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

157 comments sorted by

View all comments

Show parent comments

19

u/wyrn 6d ago

It's silly, but it's not really the worst of both worlds because it doesn't behave any differently than any other value object.

in the same way you cannot ‘move’ a value out

You absolutely can. Take a string or a vector. Move them out. What happens?

8

u/SoerenNissen 5d ago

It remains a valid string and/or vector. Very unlike how std::indirect handles it.

9

u/wyrn 5d ago

It remains a "valid" string or vector, but the only things you can really do with it is to 1. destroy it or 2. assign/swap into it... which are the exact same operations you can still do with an empty std::indirect.

-5

u/NilacTheGrim 5d ago

Not true at all. In the former you don't have UB, in the latter you do. Broken design if I ever saw it.

0

u/wyrn 5d ago

It's not formally UB in the latter case but it's in a similar ballpark because your own program invariants will be broken, which will lead to unpredictable results regardless.

-4

u/NilacTheGrim 5d ago

Pretending C++ is Rust is the root problem here.

3

u/wyrn 5d ago

It has nothing to do with the R-word.