Andrzej Krzemienski wrote:
maybe result<int, int> indeed looks suspicious, but using result<error_code, error_code> might come as quite natural:
auto select_first_error(vector<error_code> v) -> result<error_code> { if (!v.empty()) return result<error_code>{in_place_index<0>, v[0]}; else return result<error_code>{in_place_index<1>, MyErrc::NoFirstElement}; }
Yes, and the next logical step is to look at those magic constants 0 and 1 and say, hey, why not name these, would help readability. if( !v.empty() ) { return { in_place_value, v[0] }; } else { return { in_place_error, MyErrc::NoFirstElement }; } Re the multi-arg constructor, one obvious use case is this: return { errno, std::generic_category() }; or return { GetLastError(), std::system_category() }; although the main purpose is to forward arguments to custom ECs. I'm working on a prototype that showcases these but it's not ready yet.