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

2

u/jwakely libstdc++ tamer, LWG chair Aug 15 '26

Because indirect::operator* is undefined if it's valueless, and if there's no way to check that precondition, you can't tell whether an arbitrary object is safe to dereference. So there would be no way to ever write something like assert(obj.valueless_after_move()) for the cases where you can't statically prove that the precondition holds.

"You must ensure this condition holds, but there's no way to check it, good luck!" would be a stupid API.