folly::Expected

Forward declarations

Synopsis

Declared in <folly/Expected.h>

template<
    class V,
    class E>
class Expected final

Type Aliases

NameDescription
error_type The type of the contained error.
promise_type The coroutine promise type used when an Expected is a coroutine result.
rebind Rebinds this Expected to a new value type while keeping the error type.
value_type The type of the contained value.

Member Functions

NameDescription
Expected [constructor]Constructors
operator= Assignment operators
emplace Constructs a new value in place, replacing any current contents.
error Accesses the stored error, throwing if none is present.
get_pointer get_pointer overloads
hasError Reports whether the Expected holds an error.
hasValue Reports whether the Expected holds a value.
onError onError overloads
operator* Dereferences to the stored value without checking.
operator-> Accesses members of the stored value.
orElse orElse overloads
swap swap
then then overloads
thenOrThrow thenOrThrow overloads
value Accesses the stored value, throwing if none is present.
value_or Returns the stored value, or a default when in the error state.
operator bool Tests whether the Expected holds a value.

Using Declarations

Name
uninitializedByException

Friends

NameDescription
folly::expected_detail::PromiseReturnCoroutine return object that materializes an Expected from a promise.
folly::operator<Orders two Expected values, treating errors as less than values.
folly::operator==Relational Operators
folly::expected_detail::expected_detail_ExpectedHelper::ExpectedHelperStatic helpers implementing the Expected continuation operations.
folly::expected_detail::ExpectedStorageStorage backing an Expected, holding either a value or an error.
folly::ExpectedForward declarations

Non-Member Functions

NameDescription
get_pointerReturns a pointer to the value of an Expected, or null on error.
get_pointerReturns a pointer to the value of an Expected, or null on error.
makeExpectedFor constructing an Expected object from a value, with the specified Error type. Usage is as follows:
operator co_awaitEnables co_await on an Expected to unwrap its value or propagate its error.
operator!=Deleted: comparing an Expected with a bare value is not allowed.
operator!=Compares two Expected values for inequality.
operator<Deleted: comparing an Expected with a bare value is not allowed.
operator<Orders two Expected values, treating errors as less than values.
operator<=Deleted: comparing an Expected with a bare value is not allowed.
operator<=Orders two Expected values.
operator==Deleted: comparing an Expected with a bare value is not allowed.
operator==Compares two Expected values for equality.
operator>Orders two Expected values.
operator>Deleted: comparing an Expected with a bare value is not allowed.
operator>=Orders two Expected values.
operator>=Deleted: comparing an Expected with a bare value is not allowed.
parseToParse a StringPiece into a std::string_view, consuming all input.
parseToParse a StringPiece into a std::string, consuming all input.
parseToParsing strings to numeric types.
parseToParse a StringPiece into any folly string type, consuming all input.
parseToParse a StringPiece into a StringPiece (identity, consuming all input).
parseToParse a StringPiece into an fbstring, consuming all input.
parseToCustom Conversions
swapswap Expected values
tryDecodeVarintA variant of decodeVarint() that does not throw on error. Useful in contexts where only part of a serialized varint may be attempted to be decoded, e.g., when a serialized varint arrives on the boundary of a network packet.
trySplitToTry to split a string into a fixed number of fields by delimiter, using folly::tryTo<> for conversions. types by delimiter. - On success, all output values will be initialized and the 'Unit{}' value is returned. Arguments are assigned in reverse order. - On failure, the first failing 'ConversionCode' is returned with its associated substring in a 'SubstringConversionCode'. - String splitting is performed prior to each conversion; field values will not contain the delimiter. - All custom error codes are mapped to ConversionCode::CUSTOM.
tryTotryTo/to that take the strings by pointer so the caller gets information about how much of the string was consumed by the conversion. These do not check for trailing whitespace.
tryToString or StringPiece to target conversion. Accepts leading and trailing whitespace, but no non-space trailing characters.
tryToChecked conversion from any type to an enum, returning an Expected.
tryTostd::chrono::duration to struct timeval
tryTostruct timespec to std::chrono::duration
tryTostruct timeval to std::chrono::duration
tryToChecked conversion between arithmetic types, returning an Expected.
tryToEnum to anything and back
tryTotimespec or timeval to std::chrono::time_point
tryToUnchecked conversion from arithmetic to boolean. This is different from the other arithmetic conversions because we use the C convention of treating any non-zero value as true, instead of range checking.
tryTooverloadbrief to, but return an Expected
tryTostd::chrono::time_point to timespec or timeval
tryTostd::chrono::duration to struct timespec
tryToString represented as a pair of pointers to char to unsigned integrals. Assumes NO whitespace before or after.
settings::convertToLike parseTo in folly/Conv.h, but the "source" is SettingValueAndMetadata instead of a StringPiece. Defaults to folly::tryTo<T>(StringPiece) but can be overridden using ADL for user defined types.
settings::tryToConversion functions for converting a SettingValueAndMetadata to a setting type T. Implementation is similar to folly/Conv and allows for customization using the convertTo function above.