|
Multi diag tools
|
Contains a value or a error. More...
#include <Expected.h>
Collaboration diagram for Mdt::Expected< T >:Public Member Functions | |
| Expected () | |
| Construct a empty expected. More... | |
| Expected (const T &v) | |
| Construct a expected with a value. | |
| Expected (T &&v) | |
| Construct a expected with a value. | |
| Expected (const Mdt::Error &e) | |
| Construct a expected with a error. | |
| Expected (Mdt::Error &&e) | |
| Construct a expected with a error. | |
| Expected (const Expected &other) | |
| Construct a copy of other. | |
| Expected (Expected &&other) | |
| Construct by moving other. | |
| ~Expected () | |
| Destructor. | |
| Expected & | operator= (const T &v) |
| Assign a value. | |
| Expected & | operator= (T &&v) |
| Assign a value. | |
| Expected & | operator= (const Mdt::Error &e) |
| Assign a error. | |
| Expected & | operator= (Mdt::Error &&e) |
| Assign a error. | |
| Expected & | operator= (const Expected &other) |
| Assign a Expected. | |
| Expected & | operator= (Expected &&other) |
| Assign a Expected. | |
| bool | hasError () const |
| Return true if a error was set. | |
| Mdt::Error & | error () |
| Access error. More... | |
| const Mdt::Error & | error () const |
| Access error (read only) More... | |
| bool | hasValue () const |
| Return true if a value was set. | |
| T & | value () |
| Access value. More... | |
| const T & | value () const |
| Access value (read only) More... | |
| constexpr | operator bool () const noexcept |
| Return true if a value was set. | |
| T & | operator* ()& |
| Access value. More... | |
| const T & | operator* () const & |
| Access value (read only) More... | |
Contains a value or a error.
Expected provides a basic support of expected value. This is inspired from A. Alexandrescu 's talk "Systematic Error Handling in C++" : http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C
Mdt::Expected is a very limited version of the concept. For more advanced and performant version, you should take a look at the official proposal: https://github.com/viboes/std-make/tree/master/doc/proposal/expected
A function, that reads a value from a storage, could look like:
Later, a computation has to be done on the readen value:
Using all together could be:
| T | Type of value |
Definition at line 64 of file Expected.h.
|
inline |
Construct a empty expected.
A empty expected contains a null error (see Mdt::Error::isNull()).
Definition at line 73 of file Expected.h.
|
inline |
|
inline |
Access error (read only)
Definition at line 256 of file Expected.h.
|
inline |
|
inline |
Access value (read only)
Definition at line 310 of file Expected.h.
|
inline |
|
inline |
Access value (read only)
Definition at line 283 of file Expected.h.
1.8.11