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 fromexpected<E,T>
toexpected<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>
andexpected<T>
different classes.2 Introduction
Class template
expected<T,E>
proposed here is a type that may contain a value of typeT
or a value of typeE
in its storage space.T
represents the expected value,E
represents the reason explaining why it doesn’t contains a value of typeT
, that is the unexpected value. Its interface allows to query if the underlying value is either the expected value (of typeT
) or an unexpected value (of typeE
). 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 onstd::optional
N3793 [5] and Haskell monads. We can consider thatexpected<T,E>
is a generalization ofoptional<T>
providing in addition a monad interface and some specific functions associated to the unexpected typeE
. It requires no changes to core language, and breaks no existing code.
Add a Comment
Comments are closed.