folly::makeExpected

For constructing an Expected object from a value, with the specified Error type. Usage is as follows:

Synopsis

Declared in <folly/Expected.h>

template<
    class Error,
    class Value>
[[nodiscard]]
constexpr
Expected<std::decay<Value>::type, Error>
makeExpected(Value&& val);

Description

enum MyErrorCode { BAD_ERROR, WORSE_ERROR }; Expected<int, MyErrorCode> myAPI() { int i = // ...; return i ? makeExpected<MyErrorCode>(i) : makeUnexpected(BAD_ERROR); }

Return Value

An Expected in the value state holding a decayed copy of val.

NOTE

The return value should not be discarded.

Parameters

NameDescription
valThe value to wrap.