Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Andrei Alexandrescu
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Expected === '''Expected''' is a [[template (C++)|template]] class for [[C++]] which is on the C++ Standards track.<ref>[{{cite web|author1=Botet|author2=Talbot|title=A proposal to add a utility class to represent expected monad|url=http://www.hyc.io/boost/expected-proposal.pdf|url-status=dead|archive-url=https://web.archive.org/web/20140819082937/http://www.hyc.io/boost/expected-proposal.pdf|archive-date=19 August 2014}}</ref><ref>{{Cite web|url=https://github.com/viboes/std-make/blob/master/doc/proposal/expected/p0323r2.md#motivation|title=STD-make/P0323r2.md at master Β· viboes/STD-make|website=[[GitHub]]|date=21 October 2021}}</ref> Alexandrescu proposes<ref>{{cite web|last1=Alexandrescu|title=Systematic Error Handling in C++|url=http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C|url-status=dead|archive-url=https://web.archive.org/web/20130425035429/http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C|archive-date=25 April 2013}}</ref> <code>Expected<T></code> as a class for use as a return value which contains either a T or the exception preventing its creation, which is an improvement over use of either return codes or exceptions exclusively. Expected can be thought of as a restriction of sum (union) types or algebraic datatypes in various languages, e.g., [[Hope (programming language)|Hope]], or the more recent [[Haskell (programming language)|Haskell]] and [[Coq (software)|Gallina]]; or of the error handling mechanism of Google's [[Go (programming language)|Go]], or the [https://doc.rust-lang.org/std/result/ Result] type in [[Rust (programming language)|Rust]]. He explains the benefits of <code>Expected<T></code> as: * Associates errors with computational goals * Naturally allows multiple exceptions in flight * Switch between "error handling" and "exception throwing" styles * Teleportation possible across thread boundaries, across nothrow subsystem boundaries and across time (save now, throw later) * Collect, group, combine exceptions ==== Example ==== For example, instead of any of the following common function prototypes: <code> int parseInt(const string&); // Returns 0 on error and sets errno. </code> or <code> int parseInt(const string&); // Throws invalid_input or overflow </code> he proposes the following: <code> Expected<int> parseInt(const string&); // Returns an expected int: either an int or an exception </code>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Andrei Alexandrescu
(section)
Add topic