Safe, generic, stack-based discriminated union container.

The `variant` class template (inspired by Andrei Alexandrescu's class of the same name [Ale01A]) is an efficient, recursive-capable, bounded discriminated union value type capable of containing any value type (either POD or non-POD). It supports construction from any type convertible to one of its bounded types or from a source `variant` whose bounded types are each convertible to one of the destination `variant`'s bounded types. As well, through `apply_visitor`, `variant` supports compile-time checked, type-safe visitation; and through `get`, `variant` supports run-time checked, type-safe value retrieval.

Notes:

- The bounded types of the `variant` are exposed via the nested typedef `types`, which is an MPL-compatible Sequence containing the set of types that must be handled by any visitor to the `variant`.
- All members of `variant` satisfy at least the basic guarantee of exception-safety. That is, all operations on a `variant` remain defined even after previous operations have failed.
- Each type specified as a template argument to `variant` must meet the requirements of the BoundedType concept.
- Each type specified as a template argument to `variant` must be distinct after removal of qualifiers. Thus, for instance, both `variant<int, int>` and `variant<int, const int>` have undefined behavior.
- Conforming implementations of `variant` must allow at least ten types as template arguments. The exact number of allowed arguments is exposed by the preprocessor macro `BOOST_VARIANT_LIMIT_TYPES`. (See ``make_variant_over`` for a means to specify the bounded types of a `variant` by the elements of an MPL or compatible Sequence, thus overcoming this limitation.)

unspecified
unspecified
unspecified

Destroys the content of `*this`.

Will not throw.

The first bounded type of the `variant` (i.e., `T1`) must fulfill the requirements of the DefaultConstructible [20.1.4] concept.

Content of `*this` is the default value of the first bounded type (i.e, `T1`).

May fail with any exceptions arising from the default constructor of `T1`.

const variant &

Content of `*this` is a copy of the content of `other`.

May fail with any exceptions arising from the copy constructor of `other`'s contained type.

variant &&

C++11 compatible compiler.

Content of `*this` is move constructed from the content of `other`.

May fail with any exceptions arising from the move constructor of `other`'s contained type.

T &

`T` must be unambiguously convertible to one of the bounded types (i.e., `T1`, `T2`, etc.).

Content of `*this` is the best conversion of `operand` to one of the bounded types, as determined by standard overload resolution rules.

May fail with any exceptions arising from the conversion of `operand` to one of the bounded types.

const T &

Same semantics as previous constructor, but allows construction from temporaries.

T &&

C++11 compatible compiler.

Same semantics as previous constructor, but allows move construction if `operand` is an rvalue.

variant<U1, U2, ..., UN> &

Every one of `U1`, `U2`, ..., `UN` must have an unambiguous conversion to one of the bounded types (i.e., `T1`, `T2`, ..., `TN`).

If `variant<U1, U2, ..., UN>` is itself one of the bounded types, then content of `*this` is a copy of `operand`. Otherwise, content of `*this` is the best conversion of the content of `operand` to one of the bounded types, as determined by standard overload resolution rules.

If `variant<U1, U2, ..., UN>` is itself one of the bounded types, then may fail with any exceptions arising from the copy constructor of `variant<U1, U2, ..., UN>`. Otherwise, may fail with any exceptions arising from the conversion of the content of `operand` to one of the bounded types.

const variant<U1, U2, ..., UN> &

Same semantics as previous constructor, but allows construction from temporaries.

C++11 compatible compiler.

variant<U1, U2, ..., UN> &&

Same semantics as previous constructor, but allows move construction.

void

variant &

Every bounded type must fulfill the requirements of the MoveAssignable concept.

Interchanges the content of `*this` and `other`.

If the contained type of `other` is the same as the contained type of `*this`, then may fail with any exceptions arising from the `swap` of the contents of `*this` and `other`. Otherwise, may fail with any exceptions arising from either of the move or copy constructors of the contained types. Also, in the event of insufficient memory, may fail with `std::bad_alloc` (why?).

variant &

const variant &

Every bounded type must fulfill the requirements of the Assignable concept.

If the contained type of `rhs` is the same as the contained type of `*this`, then assigns the content of `rhs` into the content of `*this`. Otherwise, makes the content of `*this` a copy of the content of `rhs`, destroying the previous content of `*this`.

If the contained type of `rhs` is the same as the contained type of `*this`, then may fail with any exceptions arising from the assignment of the content of `rhs` into the content `*this`. Otherwise, may fail with any exceptions arising from the copy constructor of the contained type of `rhs`. Also, in the event of insufficient memory, may fail with `std::bad_alloc` (why?).

variant &

variant &&

- C++11 compatible compiler.
- Every bounded type must fulfill the requirements of the MoveAssignable concept.

If the contained type of `rhs` is the same as the contained type of `*this`, then move assigns the content of `rhs` into the content of `*this`. Otherwise, move constructs `*this` using the content of `rhs`, destroying the previous content of `*this`.

If the contained type of `rhs` is the same as the contained type of `*this`, then may fail with any exceptions arising from the move assignment of the content of `rhs` into the content `*this`. Otherwise, may fail with any exceptions arising from the move constructor of the contained type of `rhs`. Also, in the event of insufficient memory, may fail with `std::bad_alloc` (why?).

variant &

const T &

- `T` must be unambiguously convertible to one of the bounded types (i.e., `T1`, `T2`, etc.).
- Every bounded type must fulfill the requirements of the Assignable concept.

If the contained type of `*this` is `T`, then assigns `rhs` into the content of `*this`. Otherwise, makes the content of `*this` the best conversion of `rhs` to one of the bounded types, as determined by standard overload resolution rules, destroying the previous content of `*this`.

If the contained type of `*this` is `T`, then may fail with any exceptions arising from the assignment of `rhs` into the content `*this`. Otherwise, may fail with any exceptions arising from the conversion of `rhs` to one of the bounded types. Also, in the event of insufficient memory, may fail with `std::bad_alloc` (why?).

variant &

T &&

- C++11 compatible compiler.
- `rhs` is an rvalue. Otherwise previous operator will be used.
- `T` must be unambiguously convertible to one of the bounded types (i.e., `T1`, `T2`, etc.).
- Every bounded type must fulfill the requirements of the MoveAssignable concept.

If the contained type of `*this` is `T`, then move assigns `rhs` into the content of `*this`. Otherwise, makes the content of `*this` the best conversion of `rhs` to one of the bounded types, as determined by standard overload resolution rules, destroying the previous content of `*this`(conversion is usually done via move construction).

If the contained type of `*this` is `T`, then may fail with any exceptions arising from the move assignment of `rhs` into the content `*this`. Otherwise, may fail with any exceptions arising from the conversion of `rhs` to one of the bounded types. Also, in the event of insufficient memory, may fail with `std::bad_alloc` (why?).

int

The zero-based index into the set of bounded types of the contained type of `*this`. (For instance, if called on a `variant<int, std::string>` object containing a `std::string`, `which()` would return `1`.)

Will not throw.
bool

`false`: `variant` always contains exactly one of its bounded types. (See for more information.)

Facilitates generic compatibility with `boost::any`.

Will not throw.
const std::type_info &

`boost::variant` usues Boost.TypeIndex library so actually `const boost::typeindex::type_info &` is returned. This method is available even if RTTI is off.

`typeid(x)`, where `x` is the the content of `*this`.

Will not throw.
Equality comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the EqualityComparable concept.

`true` if `which() == rhs.which()` and `content_this == content_rhs`, where `content_this` is the content of `*this` and `content_rhs` is the content of `rhs`.

If `which() == rhs.which()` then may fail with any exceptions arising from `operator==(T,T)`, where `T` is the contained type of `*this`.

InEquality comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the EqualityComparable concept.

`true` if `!(*this == rhs)`.

If `which() == rhs.which()` then may fail with any exceptions arising from `operator==(T,T)`, where `T` is the contained type of `*this`.

LessThan comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the LessThanComparable concept.

If `which() == rhs.which()` then: `content_this < content_rhs`, where `content_this` is the content of `*this` and `content_rhs` is the content of `rhs`. Otherwise: `which() < rhs.which()`.

If `which() == rhs.which()` then may fail with any exceptions arising from `operator<(T,T)`, where `T` is the contained type of `*this`.

GreaterThan comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the LessThanComparable concept.

true if `rhs < *this`.

May fail with any exceptions arising from `operator<(T,T)`, where `T` is the contained type of `*this`.

LessThan or Equal comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the LessThanComparable concept.

true if `!(*this > rhs)`.

May fail with any exceptions arising from `operator<(T,T)`, where `T` is the contained type of `*this`.

GreaterThan or Equal comparison.
bool `const variant &`
void `const U &`

The overload returning `void` exists only to prohibit implicit conversion of the operator's right-hand side to `variant`; thus, its use will (purposefully) result in a compile-time error.

Every bounded type of the `variant` must fulfill the requirements of the LessThanComparable concept.

true if `!(*this < lhs)`.

May fail with any exceptions arising from `operator<(T,T)`, where `T` is the contained type of `*this`.

void

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

Swaps `lhs` with `rhs` by application of ``variant::swap``.

May fail with any exception arising from ``variant::swap``.

Provides streaming output for `variant` types.
std::basic_ostream<ElemType,Traits> &

std::basic_ostream<ElemType,Traits> &
const `variant`<T1, T2, ..., TN> &

Every bounded type of the `variant` must fulfill the requirements of the OutputStreamable concept.

Calls `out << x`, where `x` is the content of `rhs`.

Not available when `BOOST_NO_IOSTREAM` is defined.

Provides hashing for `variant` types so that `boost::hash` may compute hash.
std::size_t

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

Every bounded type of the `variant` must fulfill the requirements of the Hashable concept.

Calls `boost::hash<T>()(x)`, where `x` is the content of `rhs` and `T` is its type.

Actually, this function is defined in `<boost/variant/detail/hash_variant.hpp>` header.

Exposes a `variant` whose bounded types are the elements of the given type sequence.

variant< unspecified >

`type` has behavior equivalent in every respect to ``variant`< Sequence[0], Sequence[1], ... >` (where `Sequence[i]` denotes the i-th element of `Sequence`), except that no upper limit is imposed on the number of types.

Notes:

- `Sequence` must meet the requirements of MPL's Sequence concept.
- Due to standard conformance problems in several compilers, `make_variant_over` may not be supported on your compiler. See `BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT` for more information.