On 2/9/2016 3:16 AM, Niall Douglas wrote:
Something missing from the discussion so far is that expected/result/outcome MUST throw exceptions! If you try to fetch a value from a result and it contains an error, there is no alternative to throwing an exception. This fact is why I don't worry about static function initialisers and just go ahead and use error-code-via-system_error throwing constructors, ultimately you need try...catch in there one way or another.
There most certainly is an alternative! I certainly don't want this behavior. There's no way that accessing the value of a result<T> without checking for an error is not a programming error. It should be a precondition that to access the value it needs to not contain an error. It should *not* be throwing an exception because you cannot fail to satisfy the postcondition until you meet the preconditions. Undefined-behavior is the appropriate specification for accessing a value from a result that contains an error.