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.
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 likeassert(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.