boost::bad_get

The exception thrown in the event of a failed application of `boost::polymorphic_get` on the given operand value.

const char *
U *

variant
<T1, T2, ..., TN> *
const U *

const `variant`<T1, T2, ..., TN> *
U &

variant
<T1, T2, ..., TN> &
const U &

const `variant`<T1, T2, ..., TN> &

Retrieves a value of a specified type from a given ``variant``.

Unlike polymorphic_strict_get does not assert at compile time that type `U` is one of the types that can be stored in variant.

The `polymorphic_get` function allows run-time checked, type-safe retrieval of the content of the given ``variant``. The function succeeds only if the content is of the specified type `U` or of type derived from type `U`, with failure indicated as described below.

Recomendation: Use polymorphic_get or polymorphic_strict_get in new code. polymorphic_strict_get provides more compile time checks and it's behavior is closer to `std::get` from C++ Standard Library.

Warning: After either `operand` or its content is destroyed (e.g., when the given ``variant`` is assigned a value of different type), the returned reference is invalidated. Thus, significant care and caution must be extended when handling the returned reference.

As part of its guarantee of type-safety, `polymorphic_get` enforces `const`-correctness. Thus, the specified type `U` must be `const`-qualified whenever `operand` or its content is likewise `const`-qualified. The converse, however, is not required: that is, the specified type `U` may be `const`-qualified even when `operand` and its content are not.

If passed a pointer, `polymorphic_get` returns a pointer to the value content if it is of the specified type `U` or of type derived from type `U`; otherwise, a null pointer is returned. If passed a reference, `polymorphic_get` returns a reference to the value content if it is of the specified type `U` or of type derived from type `U`; otherwise, an exception is thrown (see below).

Overloads taking a ``variant`` pointer will not throw; the overloads taking a ``variant`` reference throw ``bad_polymorphic_get`` if the content is not of the specified type `U`or of type derived from type `U`.

While visitation via `apply_visitor` is generally preferred due to its greater safety, `polymorphic_get` may may be more convenient in some cases due to its straightforward usage.

U *

variant
<T1, T2, ..., TN> *
const U *

const `variant`<T1, T2, ..., TN> *
U &

variant
<T1, T2, ..., TN> &
const U &

const `variant`<T1, T2, ..., TN> &

Retrieves a value of a specified type from a given ``variant``.

Acts exactly like polymorphic_relaxed_get but does a compile time check that type `U` is one of the types that can be stored in variant.

U *

variant
<T1, T2, ..., TN> *
const U *

const `variant`<T1, T2, ..., TN> *
U &

variant
<T1, T2, ..., TN> &
const U &

const `variant`<T1, T2, ..., TN> &

Retrieves a value of a specified type from a given ``variant``.

Evaluates to polymorphic_strict_get if `BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT` is not defined. If `BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT` is defined then evaluates to polymorphic_relaxed_get.

Recomendation: Use polymorphic_get in new code without defining `BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT`. In that way polymorphic_get provides more compile time checks and it's behavior is closer to `std::get` from C++ Standard Library.