Skip to content

Do we need a of expected<T,T>::error_or function? #17

@viboes

Description

@viboes

It has been argued that the error should be always available and that often there is a success value associated to the error.

expected <E,T> would be seen more like something struct { E; optional<T> }.

The following code was show as use case

   auto e = function();
   switch (e.status()) {
     success: ....; break;
     too_green: ....; break;
     too_pink: ....; break;
}

This could be done with the current interface as follows

   auto e = function();
   switch (error_or(e, success)) {
     success: ....; break;
     too_green: ....; break;
     too_pink: ....; break;
}

where

   template <class E, class T>
   E error_or(expected<E,T> const&, E err) {
     if(e) return err;
     else return error();
   }

Do we need to add such a error_or function? as member?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions