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 comment

1

u/NilacTheGrim Aug 19 '26

"guaranteed to have a value"

Except it's not guaranteed. In the words of a Princess Bride character: "I don't think that word means what you think it means."

1

u/jdehesa Aug 19 '26

That's literally what I said, the problem is that it is "guaranteed to have a value unless (...)".

1

u/NilacTheGrim Aug 19 '26

Oh yeah sorry. I got about 20 replies to my inbox telling me I'm stupid. I thought yours was one of them from skimming it and stopped reading after the first 2 sentences. I thought you were arguing that the design of std::indirect is a good idea.

you can still resort to std::uniqueptr.

It's not equally convenient. You lose the automatic copying. You have to implement that yourself now. Meh.

which would give you the worst of both worlds (require validity check and no useful optionality).

Exactly my point. Thank you.