Awesome
expected<T>
Variations on Expected<T> by Andrei Alexandrescu.
See also expected-lite - Expected objects for C++11 and later.
Refer to this blog for more information about exception_ptr lite for C++03.
Feature Comparison
Feature | nonstd:: required | std::pair | std::optional | nonstd:: expected | Boost. Expected | Nonco expected | Andrei Expected |
---|---|---|---|---|---|---|---|
More information | see [11] | see [1] | this work | see [4] | see [3] | see [5] | |
C++03 | yes | yes | no | yes (subset) | no (union) | no | no |
C++11 | yes | yes | yes | no move sem. yet | yes | yes | yes |
DefaultConstructible | no | T param | yes | yes | no | no | no |
In-place construction | no | no | yes | no/not yet | yes | yes | no |
Literal type | no | yes | yes | no/not yet | yes | no | no |
Disengaged information | no | possible | no | yes | yes | yes | yes |
Vary disengaged type | no | yes | no | maybe | yes | no | no |
Engaged nonuse throws | yes | no | no | policy? | no | no | no |
Disengaged use throws | n/a | no | yes, value() | yes, value() | yes, get() | yes, get() | yes, get() |
Proxy (rel.ops) | no | no | yes | yes | no | no | no |
References | no | no | yes | no/not yet | no | yes | no |
Chained visitor(s) | no | no | no | maybe | maybe | no | no |
References
[1] Fernando Cacciola and Andrzej Krzemieński. A proposal to add a utility class to represent optional objects (Revision 4). ISO/IEC JTC1 SC22 WG21 N3672 2013-04-19.
[2] Andrzej Krzemieński, Optional library implementation in C++11.
[3] Anto Nonco. Extending expected<T> to deal with references. 27 May 2013.
[4] Pierre Talbot. Boost.Expected. Unofficial Boost candidate. 5 May 2013. GitHub, GSoC 2013 Proposal, boost@lists.boost.org.
[5] Andrei Alexandrescu. Systematic Error Handling in C++. Prepared for The C++and Beyond Seminar 2012. Video. Slides.
[6] Andrei Alexandrescu. Choose your Poison: Exceptions or Error Codes? (PDF). ACCU Conference 2007.
[7] Andrei Alexandrescu. The Power of None (PPT). Northwest C++ Users' Group. May 17th, 2006.
[8] Jon Jagger. A Return Type That Doesn't Like Being Ignored. Overload issue 53, February 2003.
[9] Andrei Alexandrescu. Error Handling in C++: Are we inching towards a total solution?. ACCU Conference 2002.
[10] Ken Hagan et al. Exploding return codes. comp.lang.c++.moderated. 11 February 2000.
Notes
[11] nonstd::required: templated version of Ken Hagan's ReturnCode [10].
C++11 compiler support
-
Scott Meyers. Summary of C++11 Feature Availability in gcc and MSVC. 31 January 2012.
-
C++ Rocks. C++11 compiler support shootout: Visual Studio, GCC, Clang, Intel. 14 March 2013.
Other
-
Current C++ Standard Working Draft (june 2013). N3690 (PDF).
-
Herb Sutter. Style Case Study #3: Construction Unions. GotW #85. 2009
-
Kevin T. Manley. Using Constructed Types in C++ Unions. C/C++ Users Journal, 20(8), August 2002.
-
Andrzej Krzemieński. Destructors that throw. 21 September 2011.
-
Programming in Lua, Section Relational Metamethods.
-
Jon Kalb and Dave Abrahams. Evil, or Just Misunderstood?. 17 August 2012.