Description
The return value of value_or()
is specified as follows:
Returns:
has_value() ? **this : static_cast<T>(std::forward<U>(v))
.
Meanwhile, the return value of error_or()
is specified as follows:
Returns:
std::forward<G>(e)
ifhas_value()
istrue
,error()
otherwise.
Since these functions appear to be dual in nature, it would be preferable to maintain consistent notation. Therefore, should error_or()
be modified in this way?
Returns:
has_value() ? std::forward<G>(e) : error()
.
There is another problem at this time.
value_or()
casts its argument v
using static_cast<T>(std::forward<U>(v))
. Shouldn't error_or()
similarly perform a static_cast<E>
?
When the constructor used for conversion is marked as explicit
, value_or()
will successfully perform the conversion, while error_or()
will result in a compilation error.
Here I referred to const &
overload, but &&
overload has the same problem.