expected icon indicating copy to clipboard operation
expected copied to clipboard

void -> tl::expected<void, error_type_enum> is not possible when void is return of a function, not {}

Open Gerodote opened this issue 11 months ago • 0 comments

enum class unexpected_error_find_in_map {
 NotFound,
 ShitHappened
};
void a_foo(...) { ... }

tl::expected<return_type_of_a_foo, unexpected_error_find_in_map> function(...) {
...
return a_foo(...);
}

error: could not convert ...(function place and name ) from ‘void’ to ‘tl::expected<void, unexpected_error_find_in_map>’

the problem appears when

return a_function_which_returns_void(...);

but not when

return {}

Current solution:

if constexpr( return_type_is_void ) {
the_function(...);
return {};
} else {
return the_function(...);
}

I don't know at which side the problem.

Gerodote avatar Aug 08 '23 12:08 Gerodote