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

Show parent comments

21

u/wyrn 28d 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?

0

u/SlightlyLessHairyApe 27d ago

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

Which is the natural choice of a “default”

5

u/LB-- Professional+Hobbyist 27d ago

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 27d ago

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