Andrzej Krzemienski wrote:
maybe result
indeed looks suspicious, but using result might come as quite natural: auto select_first_error(vector
v) -> result { if (!v.empty()) return result {in_place_index<0>, v[0]}; else return result {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.