folly::Optional

Optional is superseded by std::optional. Now that the C++ has a standardized implementation, Optional exists primarily for backward compatibility.

Synopsis

Declared in <folly/Optional.h>

template<class Value>
class Optional;

Type Aliases

NameDescription
promise_type The coroutine promise type that enables using Optional with co_await.
value_type The type of the value stored in the Optional.

Member Functions

NameDescription
Optional [constructor]Constructors
operator= Assignment operators
assign assign overloads
clear Set the Optional to None methodset Modifiers
emplace emplace overloads
get_pointer get_pointer overloads
hasValue Does this Optional have a value. methodset Observers
has_value Does this Optional have a value. methodset Observers
operator* Get the value. Must have value. methodset Getters
operator-> Get the value. Must have value. methodset Getters
reset Set the Optional to None methodset Modifiers
swap Swaps the contents of this Optional with another. methodset Modifiers
toStdOptional toStdOptional overloads
value Get the value. Must have value. methodset Getters
value_or value_or overloads
operator bool Does this Optional have a value. methodset Observers
operator std::optional<Value> Conversion operators

Friends

NameDescription
folly::make_optionalCreates an Optional whose value is constructed in-place from a list.
folly::make_optionalCreates an Optional whose value is constructed in-place.
folly::make_optionalCreates an Optional deducing the value type from the argument.

Non-Member Functions

NameDescription
getCurrentThreadNameEquivalent to getThreadName(std::this_thread::get_id());
getExecutorBlockingContextReturns the current thread's executor blocking context, if any is active.
getThreadNameGet the name of the given thread, or nothing if an error occurs or the functionality is not available.
get_pointerReturns a pointer to the value of an Optional, or nullptr if empty.
get_pointerReturns a pointer to the value of an Optional, or nullptr if empty.
make_optionalCreates an Optional whose value is constructed in-place from a list.
make_optionalCreates an Optional whose value is constructed in-place.
make_optionalCreates an Optional deducing the value type from the argument.
operator co_awaitEnables using folly::Optional with the co_await operator.
operator!=Compares two Optionals for inequality.
operator!=Compares an Optional with a value for inequality.
operator<Deleted to forbid ordering an Optional against a bare value.
operator<Orders two Optionals; an empty Optional sorts before any value.
operator<Orders an Optional against None; nothing sorts before None.
operator<=Orders an Optional against None.
operator<=Orders two Optionals; an empty Optional sorts before any value.
operator<=Deleted to forbid ordering an Optional against a bare value.
operator==Tests whether an Optional is empty.
operator==Compares two Optionals for equality.
operator==Compares an Optional with a value for equality.
operator>Orders two Optionals; an empty Optional sorts before any value.
operator>Orders an Optional against None; a value sorts after None.
operator>Deleted to forbid ordering an Optional against a bare value.
operator>=Deleted to forbid ordering an Optional against a bare value.
operator>=Orders an Optional against None; any value sorts at or after None.
operator>=Orders two Optionals; an empty Optional sorts before any value.
swapSwaps the contents of two Optionals.
tryUriUnescapeSimilar to tryUriUnescape above, but returning the unescaped string as a folly::Expected.
coro::timed_waitAwaits awaitable, giving up after duration elapses.
settings::getSettingsMetaReturns the metadata for a setting by name, if it exists.