proxygen
folly::Expected< Value, Error > Class Template Reference

#include <Expected.h>

Inheritance diagram for folly::Expected< Value, Error >:
folly::expected_detail::ExpectedStorage< Value, Error >

Public Types

using value_type = Value
 
using error_type = Error
 
template<class U >
using rebind = Expected< U, Error >
 

Public Member Functions

template<class B = Base, class = decltype(B{})>
 Expected () noexcept(noexcept(B{}))
 
 Expected (const Expected &that)=default
 
 Expected (Expected &&that)=default
 
template<class V , class E , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(!std::is_same< Expected< V, E >, Expected >::value &&std::is_constructible< Value, V && >::value &&std::is_constructible< Error, E && >::value)), int >::type = 0>
 Expected (Expected< V, E > that)
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Value >::value)), int >::type = 0>
constexpr Expected (const Value &val) noexcept(noexcept(Value(val)))
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Value >::value)), int >::type = 0>
constexpr Expected (Value &&val) noexcept(noexcept(Value(std::move(val))))
 
template<class T , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_convertible< T, Value >::value &&!std::is_convertible< T, Error >::value)), int >::type = 0>
constexpr Expected (T &&val) noexcept(noexcept(Value(static_cast< T && >(val))))
 
template<class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, Ts &&... >::value)), int >::type = 0>
constexpr Expected (in_place_t, Ts &&...ts) noexcept(noexcept(Value(std::declval< Ts >()...)))
 
template<class U , class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, std::initializer_list< U > &, Ts &&... >::value)), int >::type = 0>
constexpr Expected (in_place_t, std::initializer_list< U > il, Ts &&...ts) noexcept(noexcept(Value(std::declval< Ts >()...)))
 
 Expected (const Error &)=delete
 
 Expected (Error &&)=delete
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Error >::value)), int >::type = 0>
constexpr Expected (unexpected_t, const Error &err) noexcept(noexcept(Error(err)))
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Error >::value)), int >::type = 0>
constexpr Expected (unexpected_t, Error &&err) noexcept(noexcept(Error(std::move(err))))
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Error >::value)), int >::type = 0>
constexpr Expected (const Unexpected< Error > &err) noexcept(noexcept(Error(err.error())))
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Error >::value)), int >::type = 0>
constexpr Expected (Unexpected< Error > &&err) noexcept(noexcept(Error(std::move(err.error()))))
 
Expectedoperator= (const Expected &that)=default
 
Expectedoperator= (Expected &&that)=default
 
template<class V , class E , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(!std::is_same< Expected< V, E >, Expected >::value &&expected_detail::IsConvertible< V &&, Value >::value &&expected_detail::IsConvertible< E &&, Error >::value)), int >::type = 0>
Expectedoperator= (Expected< V, E > that)
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsCopyable< Value >::value)), int >::type = 0>
Expectedoperator= (const Value &val) noexcept(expected_detail::IsNothrowCopyable< Value >::value)
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsMovable< Value >::value)), int >::type = 0>
Expectedoperator= (Value &&val) noexcept(expected_detail::IsNothrowMovable< Value >::value)
 
template<class T , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_convertible< T, Value >::value &&!std::is_convertible< T, Error >::value)), int >::type = 0>
Expectedoperator= (T &&val)
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsCopyable< Error >::value)), int >::type = 0>
Expectedoperator= (const Unexpected< Error > &err) noexcept(expected_detail::IsNothrowCopyable< Error >::value)
 
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsMovable< Error >::value)), int >::type = 0>
Expectedoperator= (Unexpected< Error > &&err) noexcept(expected_detail::IsNothrowMovable< Error >::value)
 
 Expected (const expected_detail::PromiseReturn< Value, Error > &p)
 
template<class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, Ts &&... >::value)), int >::type = 0>
void emplace (Ts &&...ts)
 
void swap (Expected &that) noexcept(expected_detail::StrictAllOf< IsNothrowSwappable, Value, Error >::value)
 
Expectedoperator= (const Error &)=delete
 
Expectedoperator= (Error &&)=delete
 
constexpr bool hasValue () const noexcept
 
constexpr bool hasError () const noexcept
 
const Value & value () const &
 
Value & value ()&
 
Value && value ()&&
 
const Error & error () const &
 
Error & error ()&
 
Error && error ()&&
 
template<class U >
Value value_or (U &&dflt) const &
 
template<class U >
Value value_or (U &&dflt)&&
 
constexpr operator bool () const noexcept
 
const Value & operator* () const &
 
Value & operator* ()&
 
Value && operator* ()&&
 
const Value * operator-> () const
 
Value * operator-> ()
 
const Value * get_pointer () const &noexcept
 
Value * get_pointer ()&noexcept
 
Value * get_pointer ()&&=delete
 
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto then (Fns &&...fns) const &-> decltype(expected_detail::ExpectedHelper::then_(std::declval< const Base & >(), std::declval< Fns >()...))
 
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto then (Fns &&...fns)&-> decltype(expected_detail::ExpectedHelper::then_(std::declval< Base & >(), std::declval< Fns >()...))
 
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto then (Fns &&...fns)&&-> decltype(expected_detail::ExpectedHelper::then_(std::declval< Base && >(), std::declval< Fns >()...))
 
template<class Yes , class No = MakeBadExpectedAccess>
auto thenOrThrow (Yes &&yes, No &&no=No{}) const &-> decltype(std::declval< Yes >()(std::declval< const Value & >()))
 
template<class Yes , class No = MakeBadExpectedAccess>
auto thenOrThrow (Yes &&yes, No &&no=No{})&-> decltype(std::declval< Yes >()(std::declval< Value & >()))
 
template<class Yes , class No = MakeBadExpectedAccess>
auto thenOrThrow (Yes &&yes, No &&no=No{})&&-> decltype(std::declval< Yes >()(std::declval< Value && >()))
 

Private Types

using Base = expected_detail::ExpectedStorage< Value, Error >
 
using MakeBadExpectedAccess = typename Unexpected< Error >::MakeBadExpectedAccess
 
- Private Types inherited from folly::expected_detail::ExpectedStorage< Value, Error >
using value_type = Value
 
using error_type = Error
 

Private Member Functions

Basebase ()&
 
const Basebase () const &
 
Base && base ()&&
 
void requireValue () const
 
void requireError () const
 
expected_detail::Which which () const noexcept
 
- Private Member Functions inherited from folly::expected_detail::ExpectedStorage< Value, Error >
constexpr ExpectedStorage () noexcept(noexcept(E{}))
 
constexpr ExpectedStorage (EmptyTag) noexcept
 
constexpr ExpectedStorage (ValueTag, Vs &&...vs) noexcept(noexcept(Value(static_cast< Vs && >(vs)...)))
 
constexpr ExpectedStorage (ErrorTag, Es &&...es) noexcept(noexcept(Error(static_cast< Es && >(es)...)))
 
void clear () noexcept
 
void assignValue (Vs &&...vs)
 
void assignError (Es &&...es)
 
void assign (Other &&that)
 
Value & value ()&
 
const Value & value () const &
 
Value && value ()&&
 
FOLLY_PUSH_WARNING FOLLY_MSVC_DISABLE_WARNING (4702) Error &error()&
 
const Errorerror () const &
 
Error && error ()&&
 

Friends

template<class , class >
class Expected
 
template<class , class , expected_detail::StorageType >
struct expected_detail::ExpectedStorage
 
struct expected_detail::ExpectedHelper
 
template<class Val , class Err >
std::enable_if< IsEqualityComparable< Val >::value, bool >::type operator== (const Expected< Val, Err > &lhs, const Expected< Val, Err > &rhs)
 
template<class Val , class Err >
std::enable_if< IsLessThanComparable< Val >::value, bool >::type operator< (const Expected< Val, Err > &lhs, const Expected< Val, Err > &rhs)
 

Additional Inherited Members

- Static Private Member Functions inherited from folly::expected_detail::ExpectedStorage< Value, Error >
static constexpr bool uninitializedByException () noexcept
 
- Private Attributes inherited from folly::expected_detail::ExpectedStorage< Value, Error >
Value value_
 
Error error_
 
char ch_
 
union {
   Value   value_
 
   Error   error_
 
   char   ch_
 
}; 
 
Which which_
 

Detailed Description

template<class Value, class Error>
class folly::Expected< Value, Error >

Expected - For holding a value or an error. Useful as an alternative to exceptions, for APIs where throwing on failure would be too expensive.

Expected<Value, Error> is a variant over the types Value and Error.

Expected does not offer support for references. Use Expected<std::reference_wrapper<T>, Error> if your API needs to return a reference or an error.

Expected offers a continuation-based interface to reduce the boilerplate of checking error codes. The Expected::then member function takes a lambda that is to execute should the Expected object contain a value. The return value of the lambda is wrapped in an Expected and returned. If the lambda is not executed because the Expected contains an error, the error is returned immediately in a new Expected object.

Expected<int, Error> funcTheFirst(); Expected<std::string, Error> funcTheSecond() { return funcTheFirst().then([](int i) { return std::to_string(i); }); }

The above line of code could more verbosely written as:

Expected<std::string, Error> funcTheSecond() { if (auto ex = funcTheFirst()) { return std::to_string(*ex); } return makeUnexpected(ex.error()); }

Continuations can chain, like:

Expected<D, Error> maybeD = someFunc() .then([](A a){return B(a);}) .then([](B b){return C(b);}) .then([](C c){return D(c);});

To avoid the redundant error checking that would happen if a call at the front of the chain returns an error, these call chains can be collaped into a single call to .then:

Expected<D, Error> maybeD = someFunc() .then([](A a){return B(a);}, [](B b){return C(b);}, [](C c){return D(c);});

The result of .then() is wrapped into Expected< ~, Error > if it isn't of that form already. Consider the following code:

extern Expected<std::string, Error> readLineFromIO(); extern Expected<int, Error> parseInt(std::string); extern int increment(int);

Expected<int, Error> x = readLineFromIO().then(parseInt).then(increment);

From the code above, we see that .then() works both with functions that return an Expected< ~, Error > (like parseInt) and with ones that return a plain value (like increment). In the case of parseInt, .then() returns the result of parseInt as-is. In the case of increment, it wraps the int that increment returns into an Expected< int, Error >.

Sometimes when using a continuation you would prefer an exception to be thrown for a value-less Expected. For that you can use .thenOrThrow, as follows:

B b = someFunc() .thenOrThrow([](A a){return B(a);});

The above call to thenOrThrow will invoke the lambda if the Expected returned by someFunc() contains a value. Otherwise, it will throw an exception of type Unexpected<Error>::BadExpectedAccess. If you prefer it throw an exception of a different type, you can pass a second lambda to thenOrThrow:

B b = someFunc() .thenOrThrow([](A a){return B(a);}, [](Error e) {throw MyException(e);});

Like C++17's std::variant, Expected offers the almost-never-empty guarantee; that is, an Expected<Value, Error> almost always contains either a Value or and Error. Partially-formed Expected objects occur when an assignment to an Expected object that would change the type of the contained object (Value- to-Error or vice versa) throws. Trying to access either the contained value or error object causes Expected to throw folly::BadExpectedAccess.

Expected models OptionalPointee, so calling 'get_pointer(ex)' will return a pointer to nullptr if the 'ex' is in the error state, and a pointer to the value otherwise:

Expected<int, Error> maybeInt = ...; if (int* v = get_pointer(maybeInt)) { cout << *v << endl; }

Definition at line 78 of file Expected.h.

Member Typedef Documentation

template<class Value, class Error>
using folly::Expected< Value, Error >::Base = expected_detail::ExpectedStorage<Value, Error>
private

Definition at line 892 of file Expected.h.

template<class Value, class Error>
using folly::Expected< Value, Error >::error_type = Error

Definition at line 907 of file Expected.h.

template<class Value, class Error>
using folly::Expected< Value, Error >::MakeBadExpectedAccess = typename Unexpected<Error>::MakeBadExpectedAccess
private

Definition at line 894 of file Expected.h.

template<class Value, class Error>
template<class U >
using folly::Expected< Value, Error >::rebind = Expected<U, Error>

Definition at line 910 of file Expected.h.

template<class Value, class Error>
using folly::Expected< Value, Error >::value_type = Value

Definition at line 906 of file Expected.h.

Constructor & Destructor Documentation

template<class Value, class Error>
template<class B = Base, class = decltype(B{})>
folly::Expected< Value, Error >::Expected ( )
inlinenoexcept

Definition at line 923 of file Expected.h.

923 {})) : Base{} {}
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
folly::Expected< Value, Error >::Expected ( const Expected< Value, Error > &  that)
default
template<class Value, class Error>
folly::Expected< Value, Error >::Expected ( Expected< Value, Error > &&  that)
default
template<class Value, class Error>
template<class V , class E , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(!std::is_same< Expected< V, E >, Expected >::value &&std::is_constructible< Value, V && >::value &&std::is_constructible< Error, E && >::value)), int >::type = 0>
folly::Expected< Value, Error >::Expected ( Expected< V, E that)
inline

Definition at line 933 of file Expected.h.

933  : Base{expected_detail::EmptyTag{}} {
934  *this = std::move(that);
935  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Value >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( const Value &  val)
inlinenoexcept

Definition at line 938 of file Expected.h.

940  : Base{expected_detail::ValueTag{}, val} {}
double val
Definition: String.cpp:273
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Value >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( Value &&  val)
inlinenoexcept

Definition at line 943 of file Expected.h.

945  : Base{expected_detail::ValueTag{}, std::move(val)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
double val
Definition: String.cpp:273
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<class T , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_convertible< T, Value >::value &&!std::is_convertible< T, Error >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( T &&  val)
inlinenoexcept

Definition at line 950 of file Expected.h.

952  : Base{expected_detail::ValueTag{}, static_cast<T&&>(val)} {}
double val
Definition: String.cpp:273
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
folly::std T
template<class Value, class Error>
template<class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, Ts &&... >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( in_place_t  ,
Ts &&...  ts 
)
inlineexplicitnoexcept

Definition at line 956 of file Expected.h.

958  : Base{expected_detail::ValueTag{}, static_cast<Ts&&>(ts)...} {}
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<class U , class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, std::initializer_list< U > &, Ts &&... >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( in_place_t  ,
std::initializer_list< U >  il,
Ts &&...  ts 
)
inlineexplicitnoexcept

Definition at line 965 of file Expected.h.

969  : Base{expected_detail::ValueTag{}, il, static_cast<Ts&&>(ts)...} {}
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
folly::Expected< Value, Error >::Expected ( const Error &  )
delete
template<class Value, class Error>
folly::Expected< Value, Error >::Expected ( Error &&  )
delete
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Error >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( unexpected_t  ,
const Error &  err 
)
inlinenoexcept

Definition at line 977 of file Expected.h.

979  : Base{expected_detail::ErrorTag{}, err} {}
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Error >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( unexpected_t  ,
Error &&  err 
)
inlinenoexcept

Definition at line 982 of file Expected.h.

984  : Base{expected_detail::ErrorTag{}, std::move(err)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_copy_constructible< Error >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( const Unexpected< Error > &  err)
inlinenoexcept

Definition at line 987 of file Expected.h.

989  : Base{expected_detail::ErrorTag{}, err.error()} {}
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
const Error & error() const &
Definition: Expected.h:255
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_move_constructible< Error >::value)), int >::type = 0>
constexpr folly::Expected< Value, Error >::Expected ( Unexpected< Error > &&  err)
inlinenoexcept

Definition at line 992 of file Expected.h.

994  : Base{expected_detail::ErrorTag{}, std::move(err.error())} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
expected_detail::ExpectedStorage< Value, Error > Base
Definition: Expected.h:892
template<class Value, class Error>
folly::Expected< Value, Error >::Expected ( const expected_detail::PromiseReturn< Value, Error > &  p)
inline

Definition at line 1050 of file Expected.h.

1051  : Expected{} {
1052  p.promise_->value_ = this;
1053  }
Expected() noexcept(noexcept(B{}))
Definition: Expected.h:923

Member Function Documentation

template<class Value, class Error>
Base& folly::Expected< Value, Error >::base ( )
inlineprivate

Definition at line 895 of file Expected.h.

895  {
896  return *this;
897  }
template<class Value, class Error>
const Base& folly::Expected< Value, Error >::base ( ) const
inlineprivate

Definition at line 898 of file Expected.h.

898  {
899  return *this;
900  }
template<class Value, class Error>
Base&& folly::Expected< Value, Error >::base ( )
inlineprivate

Definition at line 901 of file Expected.h.

901  {
902  return std::move(*this);
903  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, class Error>
template<class... Ts, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_constructible< Value, Ts &&... >::value)), int >::type = 0>
void folly::Expected< Value, Error >::emplace ( Ts &&...  ts)
inline

Definition at line 1057 of file Expected.h.

Referenced by folly::TEST().

1057  {
1058  this->assignValue(static_cast<Ts&&>(ts)...);
1059  }
template<class Value, class Error>
const Error& folly::Expected< Value, Error >::error ( ) const
inline

Definition at line 1132 of file Expected.h.

Referenced by folly::makeExpected(), and folly::TEST().

1132  {
1133  requireError();
1134  return this->Base::error();
1135  }
void requireError() const
Definition: Expected.h:1282
template<class Value, class Error>
Error& folly::Expected< Value, Error >::error ( )
inline

Definition at line 1137 of file Expected.h.

1137  {
1138  requireError();
1139  return this->Base::error();
1140  }
void requireError() const
Definition: Expected.h:1282
template<class Value, class Error>
Error&& folly::Expected< Value, Error >::error ( )
inline

Definition at line 1142 of file Expected.h.

1142  {
1143  requireError();
1144  return std::move(this->Base::error());
1145  }
void requireError() const
Definition: Expected.h:1282
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, class Error>
const Value* folly::Expected< Value, Error >::get_pointer ( ) const
inlinenoexcept

Definition at line 1188 of file Expected.h.

1188  {
1189  return hasValue() ? std::addressof(this->value_) : nullptr;
1190  }
constexpr bool hasValue() const noexcept
Definition: Expected.h:1107
#define nullptr
Definition: http_parser.c:41
template<class Value, class Error>
Value* folly::Expected< Value, Error >::get_pointer ( )
inlinenoexcept

Definition at line 1192 of file Expected.h.

1192  {
1193  return hasValue() ? std::addressof(this->value_) : nullptr;
1194  }
constexpr bool hasValue() const noexcept
Definition: Expected.h:1107
#define nullptr
Definition: http_parser.c:41
template<class Value, class Error>
Value* folly::Expected< Value, Error >::get_pointer ( )
delete
template<class Value, class Error>
constexpr bool folly::Expected< Value, Error >::hasError ( ) const
inlinenoexcept

Definition at line 1111 of file Expected.h.

Referenced by folly::operator<(), and folly::operator==().

template<class Value, class Error>
constexpr bool folly::Expected< Value, Error >::hasValue ( ) const
inlinenoexcept

Definition at line 1107 of file Expected.h.

Referenced by folly::makeExpected(), and folly::TEST().

template<class Value, class Error>
constexpr folly::Expected< Value, Error >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 1164 of file Expected.h.

1164  {
1165  return hasValue();
1166  }
constexpr bool hasValue() const noexcept
Definition: Expected.h:1107
template<class Value, class Error>
const Value& folly::Expected< Value, Error >::operator* ( ) const
inline

Definition at line 1168 of file Expected.h.

1168  {
1169  return this->value();
1170  }
const Value & value() const &
Definition: Expected.h:1117
template<class Value, class Error>
Value& folly::Expected< Value, Error >::operator* ( )
inline

Definition at line 1172 of file Expected.h.

1172  {
1173  return this->value();
1174  }
const Value & value() const &
Definition: Expected.h:1117
template<class Value, class Error>
Value&& folly::Expected< Value, Error >::operator* ( )
inline

Definition at line 1176 of file Expected.h.

1176  {
1177  return std::move(this->value());
1178  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const Value & value() const &
Definition: Expected.h:1117
template<class Value, class Error>
const Value* folly::Expected< Value, Error >::operator-> ( ) const
inline

Definition at line 1180 of file Expected.h.

1180  {
1181  return std::addressof(this->value());
1182  }
const Value & value() const &
Definition: Expected.h:1117
template<class Value, class Error>
Value* folly::Expected< Value, Error >::operator-> ( )
inline

Definition at line 1184 of file Expected.h.

1184  {
1185  return std::addressof(this->value());
1186  }
const Value & value() const &
Definition: Expected.h:1117
template<class Value, class Error>
Expected& folly::Expected< Value, Error >::operator= ( const Expected< Value, Error > &  that)
default
template<class Value, class Error>
Expected& folly::Expected< Value, Error >::operator= ( Expected< Value, Error > &&  that)
default
template<class Value, class Error>
template<class V , class E , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(!std::is_same< Expected< V, E >, Expected >::value &&expected_detail::IsConvertible< V &&, Value >::value &&expected_detail::IsConvertible< E &&, Error >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( Expected< V, E that)
inline

Definition at line 1008 of file Expected.h.

1008  {
1009  this->assign(std::move(that));
1010  return *this;
1011  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsCopyable< Value >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( const Value &  val)
inlinenoexcept

Definition at line 1014 of file Expected.h.

1015  {
1016  this->assignValue(val);
1017  return *this;
1018  }
double val
Definition: String.cpp:273
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsMovable< Value >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( Value &&  val)
inlinenoexcept

Definition at line 1021 of file Expected.h.

1022  {
1023  this->assignValue(std::move(val));
1024  return *this;
1025  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
double val
Definition: String.cpp:273
template<class Value, class Error>
template<class T , bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(std::is_convertible< T, Value >::value &&!std::is_convertible< T, Error >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( T &&  val)
inline

Definition at line 1030 of file Expected.h.

1030  {
1031  this->assignValue(static_cast<T&&>(val));
1032  return *this;
1033  }
double val
Definition: String.cpp:273
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsCopyable< Error >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( const Unexpected< Error > &  err)
inlinenoexcept

Definition at line 1036 of file Expected.h.

1037  {
1038  this->assignError(err.error());
1039  return *this;
1040  }
template<class Value, class Error>
template<bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(expected_detail::IsMovable< Error >::value)), int >::type = 0>
Expected& folly::Expected< Value, Error >::operator= ( Unexpected< Error > &&  err)
inlinenoexcept

Definition at line 1043 of file Expected.h.

1044  {
1045  this->assignError(std::move(err.error()));
1046  return *this;
1047  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, class Error>
Expected& folly::Expected< Value, Error >::operator= ( const Error &  )
delete
template<class Value, class Error>
Expected& folly::Expected< Value, Error >::operator= ( Error &&  )
delete
template<class Value, class Error>
void folly::Expected< Value, Error >::requireError ( ) const
inlineprivate

Definition at line 1282 of file Expected.h.

1282  {
1283  if (UNLIKELY(!hasError())) {
1284  throw_exception<BadExpectedAccess>();
1285  }
1286  }
constexpr bool hasError() const noexcept
Definition: Expected.h:1111
#define UNLIKELY(x)
Definition: Likely.h:48
template<class Value, class Error>
void folly::Expected< Value, Error >::requireValue ( ) const
inlineprivate

Definition at line 1272 of file Expected.h.

1272  {
1273  if (UNLIKELY(!hasValue())) {
1274  if (LIKELY(hasError())) {
1275  using Err = typename Unexpected<Error>::BadExpectedAccess;
1276  throw_exception<Err>(this->error_);
1277  }
1278  throw_exception<BadExpectedAccess>();
1279  }
1280  }
constexpr bool hasValue() const noexcept
Definition: Expected.h:1107
#define LIKELY(x)
Definition: Likely.h:47
constexpr bool hasError() const noexcept
Definition: Expected.h:1111
#define UNLIKELY(x)
Definition: Likely.h:48
template<class Value, class Error>
void folly::Expected< Value, Error >::swap ( Expected< Value, Error > &  that)
inlinenoexcept

swap

Definition at line 1064 of file Expected.h.

Referenced by folly::TEST().

1065  {
1066  if (this->uninitializedByException() || that.uninitializedByException()) {
1067  throw_exception<BadExpectedAccess>();
1068  }
1069  using std::swap;
1070  if (*this) {
1071  if (that) {
1072  swap(this->value_, that.value_);
1073  } else {
1074  Error e(std::move(that.error_));
1075  that.assignValue(std::move(this->value_));
1076  this->assignError(std::move(e));
1077  }
1078  } else {
1079  if (!that) {
1080  swap(this->error_, that.error_);
1081  } else {
1082  Error e(std::move(this->error_));
1083  this->assignValue(std::move(that.value_));
1084  that.assignError(std::move(e));
1085  }
1086  }
1087  }
folly::exception_wrapper Error
Definition: types.h:24
void swap(Expected &that) noexcept(expected_detail::StrictAllOf< IsNothrowSwappable, Value, Error >::value)
Definition: Expected.h:1064
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void swap(Expected< Value, Error > &lhs, Expected< Value, Error > &rhs) noexcept(expected_detail::StrictAllOf< IsNothrowSwappable, Value, Error >::value)
Definition: Expected.h:1368
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto folly::Expected< Value, Error >::then ( Fns &&...  fns) const -> decltype( expected_detail::ExpectedHelper::then_( std::declval<const Base&>(), std::declval<Fns>()...))
inline

then

Definition at line 1202 of file Expected.h.

1205  {
1206  if (this->uninitializedByException()) {
1207  throw_exception<BadExpectedAccess>();
1208  }
1209  return expected_detail::ExpectedHelper::then_(
1210  base(), static_cast<Fns&&>(fns)...);
1211  }
Base & base()&
Definition: Expected.h:895
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto folly::Expected< Value, Error >::then ( Fns &&...  fns) -> decltype(expected_detail::ExpectedHelper::then_( std::declval<Base&>(), std::declval<Fns>()...))
inline

Definition at line 1214 of file Expected.h.

1216  {
1217  if (this->uninitializedByException()) {
1218  throw_exception<BadExpectedAccess>();
1219  }
1220  return expected_detail::ExpectedHelper::then_(
1221  base(), static_cast<Fns&&>(fns)...);
1222  }
Base & base()&
Definition: Expected.h:895
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class... Fns, bool FB_CONCATENATE = false, typename std::enable_if< (FB_CONCATENATE(FB_CONCATENATE(Folly, Requires), __LINE__)||static_cast< bool >(sizeof...(Fns) > = 1>
auto folly::Expected< Value, Error >::then ( Fns &&...  fns) -> decltype(expected_detail::ExpectedHelper::then_( std::declval<Base&&>(), std::declval<Fns>()...))
inline

Definition at line 1225 of file Expected.h.

1227  {
1228  if (this->uninitializedByException()) {
1229  throw_exception<BadExpectedAccess>();
1230  }
1231  return expected_detail::ExpectedHelper::then_(
1232  std::move(base()), static_cast<Fns&&>(fns)...);
1233  }
Base & base()&
Definition: Expected.h:895
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class Yes , class No = MakeBadExpectedAccess>
auto folly::Expected< Value, Error >::thenOrThrow ( Yes &&  yes,
No &&  no = No{} 
) const -> decltype( std::declval<Yes>()(std::declval<const Value&>()))
inline

thenOrThrow

Definition at line 1239 of file Expected.h.

1239  {}) const& -> decltype(
1240  std::declval<Yes>()(std::declval<const Value&>())) {
1241  using Ret = decltype(std::declval<Yes>()(std::declval<const Value&>()));
1242  if (this->uninitializedByException()) {
1243  throw_exception<BadExpectedAccess>();
1244  }
1245  return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
1246  base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
1247  }
Base & base()&
Definition: Expected.h:895
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class Yes , class No = MakeBadExpectedAccess>
auto folly::Expected< Value, Error >::thenOrThrow ( Yes &&  yes,
No &&  no = No{} 
) -> decltype( std::declval<Yes>()(std::declval<Value&>()))
inline

Definition at line 1250 of file Expected.h.

1250  {}) & -> decltype(
1251  std::declval<Yes>()(std::declval<Value&>())) {
1252  using Ret = decltype(std::declval<Yes>()(std::declval<Value&>()));
1253  if (this->uninitializedByException()) {
1254  throw_exception<BadExpectedAccess>();
1255  }
1256  return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
1257  base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
1258  }
Base & base()&
Definition: Expected.h:895
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
template<class Yes , class No = MakeBadExpectedAccess>
auto folly::Expected< Value, Error >::thenOrThrow ( Yes &&  yes,
No &&  no = No{} 
) -> decltype( std::declval<Yes>()(std::declval<Value&&>()))
inline

Definition at line 1261 of file Expected.h.

1261  {}) && -> decltype(
1262  std::declval<Yes>()(std::declval<Value&&>())) {
1263  using Ret = decltype(std::declval<Yes>()(std::declval<Value&&>()));
1264  if (this->uninitializedByException()) {
1265  throw_exception<BadExpectedAccess>();
1266  }
1267  return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
1268  std::move(base()), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
1269  }
Base & base()&
Definition: Expected.h:895
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static constexpr bool uninitializedByException() noexcept
Definition: Expected.h:209
template<class Value, class Error>
const Value& folly::Expected< Value, Error >::value ( ) const
inline

Definition at line 1117 of file Expected.h.

Referenced by folly::makeExpected(), and folly::TEST().

1117  {
1118  requireValue();
1119  return this->Base::value();
1120  }
void requireValue() const
Definition: Expected.h:1272
template<class Value, class Error>
Value& folly::Expected< Value, Error >::value ( )
inline

Definition at line 1122 of file Expected.h.

1122  {
1123  requireValue();
1124  return this->Base::value();
1125  }
void requireValue() const
Definition: Expected.h:1272
template<class Value, class Error>
Value&& folly::Expected< Value, Error >::value ( )
inline

Definition at line 1127 of file Expected.h.

1127  {
1128  requireValue();
1129  return std::move(this->Base::value());
1130  }
void requireValue() const
Definition: Expected.h:1272
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, class Error>
template<class U >
Value folly::Expected< Value, Error >::value_or ( U &&  dflt) const
inline

Definition at line 1149 of file Expected.h.

Referenced by folly::TEST().

1149  {
1151  return this->value_;
1152  }
1153  return static_cast<U&&>(dflt);
1154  }
#define LIKELY(x)
Definition: Likely.h:47
template<class Value, class Error>
template<class U >
Value folly::Expected< Value, Error >::value_or ( U &&  dflt)
inline

Definition at line 1157 of file Expected.h.

1157  {
1159  return std::move(this->value_);
1160  }
1161  return static_cast<U&&>(dflt);
1162  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define LIKELY(x)
Definition: Likely.h:47
template<class Value, class Error>
expected_detail::Which folly::Expected< Value, Error >::which ( ) const
inlineprivatenoexcept

Definition at line 1288 of file Expected.h.

1288  {
1289  return this->which_;
1290  }

Friends And Related Function Documentation

template<class Value, class Error>
template<class , class >
friend class Expected
friend

Definition at line 888 of file Expected.h.

template<class Value, class Error>
friend struct expected_detail::ExpectedHelper
friend

Definition at line 891 of file Expected.h.

template<class Value, class Error>
template<class , class , expected_detail::StorageType >
friend struct expected_detail::ExpectedStorage
friend

Definition at line 890 of file Expected.h.

template<class Value, class Error>
template<class Val , class Err >
std::enable_if<IsLessThanComparable<Val>::value, bool>::type operator< ( const Expected< Val, Err > &  lhs,
const Expected< Val, Err > &  rhs 
)
friend
template<class Value, class Error>
template<class Val , class Err >
std::enable_if<IsEqualityComparable<Val>::value, bool>::type operator== ( const Expected< Val, Err > &  lhs,
const Expected< Val, Err > &  rhs 
)
friend

Relational Operators


The documentation for this class was generated from the following file: