Add folly::Expected, an alternative to exceptions for non-throwing APIs that can...
authorEric Niebler <eniebler@fb.com>
Mon, 15 Aug 2016 17:20:25 +0000 (10:20 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Mon, 15 Aug 2016 17:23:27 +0000 (10:23 -0700)
commit4d932ecc53c7a72267179e58eeed7ec56eb7dc53
tree26e7ebd11277a864a8a40507c9a2d369638154e9
parent73f2085759f2dc872bf23f90d8bd354445433c01
Add folly::Expected, an alternative to exceptions for non-throwing APIs that can fail.

Summary:
Expected is like an Optional with extra state for reporting //why// the Expected is empty. Something like it is currently under review for inclusion in the C++ standard [1], and Andrei Alexandrescu has spoken about it [2]. It corresponds to the Either Monad in Haskell, where it is used as a return type of an API that has more than one failure mode.

By adding folly::Expected, we get a way to implement non-throwing APIs with a consistent and composable interface.

[^1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4015.pdf
[^2]: https://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C

Reviewed By: mhx

Differential Revision: D3522501

fbshipit-source-id: 48b8ea2dfbd0769f26ec84d2d52fd41db75dc05a
folly/Expected.h [new file with mode: 0644]
folly/Makefile.am
folly/Optional.h
folly/Traits.h
folly/test/ExpectedTest.cpp [new file with mode: 0644]
folly/test/Makefile.am
folly/test/TraitsTest.cpp