folly::tryTo

Checked conversion from any type to an enum, returning an Expected.

Synopsis

Declared in <folly/Conv.h>

template<
    class Tgt,
    class Src>
Expected<Tgt, ConversionCode>
tryTo(Src const& value) noexcept
requires !std::is_convertible<Src, StringPiece>::value && std::is_enum<Tgt>::value &&
        !std::is_same<Src, Tgt>::value;

Return Value

An Expected holding the converted enum value, or an error code.

Parameters

NameDescription
valueThe value to convert to the enum.