
Niall Douglas wrote:
template<class T> class result { public:
result(); // T() or error, legitimate fork
result( T const& ); result( T&& );
result( std::error_code const& ) noexcept;
result( result const& ); result( result&& );
result( outcome const& ); //? result( outcome && ); //?
bool has_value() const noexcept; bool has_error() const noexcept;
T value() const; T value() &&;
std::error_code error() const;
explicit operator bool() const noexcept;
void swap( result& ) noexcept; };
That's literally it.
You're missing a few bits of necessary stuff, like equality operators, initialiser list construction and so on.
Equality yes, initializer list no. This works: #include <vector> #include <system_error> template<class T> class result { private: T t_; public: result( T const& t ): t_( t ) { } result( T&& t ): t_( std::move( t ) ) { } result( std::error_code const & ) { } }; int main() { result<std::vector<int>> r{ { 1, 2, 3 } }; }
But essentially you've just specified Vicente's Expected there.
I don't think I have. Expected has more members.