N4109: A proposal to add a utility class to represent expected monad -- R1 -- V Escriba, P Talbot

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4109

Date: 2014-06-29

A proposal to add a utility class to represent expected monad -- Revision 1

by Vicente J. Botet Escriba and Pierre Talbot

Excerpt:

1 History

R1- Revision of N4015 [9] after Rapperswil feedback:

  • Switch the expected class template parameter order from expected<E,T> to expected<T,E>.
  • Make the unexpected value a salient attribute of the expected class concerning the relational operators.
  • Removed open point about making expected<T,E> and expected<T> different classes.

2 Introduction

Class template expected<T,E> proposed here is a type that may contain a value of type T or a value of type E in its storage space. T represents the expected value, E represents the reason explaining why it doesn’t contains a value of type T, that is the unexpected value. Its interface allows to query if the underlying value is either the expected value (of type T) or an unexpected value (of type E). The original idea comes from Andrei Alexandrescu C++ and Beyond 2012: Systematic Error Handling in C++ talk [2]. The interface and the rational are based on std::optional N3793 [5] and Haskell monads. We can consider that expected<T,E> is a generalization of optional<T> providing in addition a monad interface and some specific functions associated to the unexpected type E. It requires no changes to core language, and breaks no existing code.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.