folly::DiscriminatedPtr

Discriminated pointer.

Synopsis

Declared in <folly/DiscriminatedPtr.h>

template<typename... Types>
class DiscriminatedPtr;

Description

Given a list of types, a DiscriminatedPtr<Types...> may point to an object of one of the given types, or may be empty. DiscriminatedPtr is type-safe: you may only get a pointer to the type that you put in, otherwise get throws an exception (and get_nothrow returns nullptr)

This pointer does not do any kind of lifetime management -- it's not a "smart" pointer. You are responsible for deallocating any memory used to hold pointees, if necessary.

Member Functions

NameDescription
DiscriminatedPtr [constructor]Constructors
operator= Assignment operator from a pointer of type T.
apply apply overloads
clear Clear this DiscriminatedPtr, making it empty.
empty Return true iff this DiscriminatedPtr is empty.
get get overloads
get_nothrow get_nothrow overloads
hasType Return true iff the object pointed by this DiscriminatedPtr has type T, false otherwise. Fails at compile time if T is not a valid type (listed in Types...)
index Get the 1-based type index of the type currently stored in this pointer. Returns 0 if the pointer is empty.
set Set this DiscriminatedPtr to point to an object of type T. Fails at compile time if T is not a valid type (listed in Types)