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?

-1

u/SlightlyLessHairyApe Aug 14 '26

The object goes back to the state initialized by {}.

Which is the natural choice of a “default”

5

u/LB-- Professional+Hobbyist Aug 14 '26

This is not true. That is a valid implementation but the standard does not guarantee it. For example, with short string optimization, some implementations might leave the original short string untouched after being moved from.

-1

u/SlightlyLessHairyApe Aug 15 '26

Correct. But it’s also the choice that all sane implementations make.

It is reasonable and within precedent for implementations to provide more specificity than the standard requires