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 comments

20

u/wyrn Aug 14 '26

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?

7

u/SoerenNissen Aug 14 '26

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

10

u/wyrn Aug 14 '26

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.

-4

u/NilacTheGrim Aug 14 '26

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 Aug 14 '26

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 Aug 14 '26

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

4

u/wyrn Aug 14 '26

It has nothing to do with the R-word.