Hacker News new | ask | show | jobs
by Someone 1887 days ago
> it would be nice if you could get an assert in operator*

If, as you wrote, operator* for an optional that doesn’t contain a value is UB, it can do whatever it wants, including assert.

I think the problem is that there’s an implicit requirement that operator* optionals that do contain a value is as fast as a pointer dereference.

(Aside: reading https://en.cppreference.com/w/cpp/utility/optional, I wonder how one can misuse “When an object of type optional<T> is contextually converted to bool, the conversion returns true if the object contains a value and false if it does not contain a value.” to write obfuscated code or hide back doors using optional<bool>)

1 comments

well, the immediate problem is it's hard to rewrite the STL without resorting to ugly patches