Template Function handle_expected

Function Documentation

template<typename Expected>
Expected::value_type handle_expected(Expected &&result)

Helper function for checking if a tl::expected return type has a value or an error.

If a value exists, we return it as is. When handling unexpected values, if the error is string convertible then we can pass it along through a std::runtime_error. Otherwise we do not know the details of the underlying exception.

Throws:

std::runtime_error – if the result is an error.

Returns:

The unwrapped value, or throw an exception.