[#bsl-variant]
= xref:bsl.adoc[bsl]::variant
:relfileprefix: ../
:mrdocs:

== Synopsis

Declared in `&lt;bslstl&lowbar;variant&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;HEAD,
    class&period;&period;&period; t&lowbar;TAIL&gt;
class variant;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/variant/allocator_type.adoc[`allocator&lowbar;type`] 
| Type alias to the allocator type used by `variant`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/variant/2constructor-0e.adoc[`variant`]         [.small]#[constructor]#
| Constructors
| xref:bsl/variant/operator_assign-07.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/variant/emplace-03.adoc[`emplace`] 
| `emplace` overloads
| xref:bsl/variant/get_allocator.adoc[`get&lowbar;allocator`] 
| Return a copy of this object&apos;s allocator&period; At least one alternative of this `variant` object shall be allocator&hyphen;aware&semi; in C&plus;&plus;03, due to language limitations, this method can be called even if no alternative is allocator&hyphen;aware, but returns a non&hyphen;allocator type in that case&period;
| xref:bsl/variant/index.adoc[`index`] 
| Return the index of the alternative currently managed by this `variant` object, or `bsl&colon;&colon;variant&lowbar;npos` if this object is valueless by exception&period; This method differs from the standard in the following way&colon; &ast; `constexpr` is not implemented This is because no constructors are currently constexpr and there is no way to test the constexpr property of this function&period;
| xref:bsl/variant/swap.adoc[`swap`] 
| Efficiently exchange the value of this object with the value of the specified `other` object&period; This method provides the no&hyphen;throw exception&hyphen;safety guarantee if the two swapped objects contain the same alternative and if that alternative `t&lowbar;TYPE` provides that guarantee&period; If `&ast;this` and `other` do not have the same active alternative and this method exits via an exception, either or both `variant` objects may be left in a valueless state or with an contained value in a moved&hyphen;from state&period; The behavior is undefined unless `&ast;this` has the same allocator as `other`&period; All alternatives shall be move constructible and swappable&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; `constexpr` is not implemented &ast; `noexcept` specification is not implemented
| xref:bsl/variant/valueless_by_exception.adoc[`valueless&lowbar;by&lowbar;exception`] 
| Return `false` if there is an alternative object currently managed by this `variant` object, and `true` otherwise&period; A `variant` object can become valueless by exception if the creation of an alternative object exits via an exception, or if it is copied or assigned from another `variant` object that is valueless by exception&period; This method differs from the standard in the following way&colon; &ast; `constexpr` is not implemented This is because no constructors are currently constexpr and there is no way to test the constexpr property of this function&period;
| xref:bsl/variant/2conversion-0e.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;variant, IsBitwiseMoveable, (BloombergLP&colon;&colon;bslstl&colon;&colon;Variant&lowbar;IsBitwiseMoveableAll&lt;t&lowbar;HEAD, t&lowbar;TAIL&period;&period;&period;&gt;&colon;&colon;value)&gt;`] 
| Nested trait declaration for `IsBitwiseMoveable`&period;
| xref:bsl/variant/2conversion-02.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;variant, UsesAllocatorArgT, (BloombergLP&colon;&colon;bslstl&colon;&colon;Variant&lowbar;UsesBslmaAllocatorAny&lt;t&lowbar;HEAD, t&lowbar;TAIL&period;&period;&period;&gt;&colon;&colon;value)&gt;`] 
| Nested trait declaration for `UsesAllocatorArgT`&period;
| xref:bsl/variant/2conversion-0b.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;variant, UsesBslmaAllocator, (BloombergLP&colon;&colon;bslstl&colon;&colon;Variant&lowbar;UsesBslmaAllocatorAny&lt;t&lowbar;HEAD, t&lowbar;TAIL&period;&period;&period;&gt;&colon;&colon;value)&gt;`] 
| Nested trait declaration for `UsesBslmaAllocator`&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bslstl/Variant_Base.adoc[BloombergLP::bslstl::Variant&lowbar;Base]`
| This component&hyphen;private struct defines the data representation of `bsl&colon;&colon;variant` and contains the implementations of its special member functions (which must be defaulted in `bsl&colon;&colon;variant` itself)&period; This class also contains implementations of additional constructors and methods needed for the correct functionality of the `variant` class hierarchy&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/get-002.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get-035.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get-06.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get-0b5.adoc[`get`]
| Return a reference to the alternative object at index (template parameter) `t&lowbar;INDEX` in the specified `obj`&period; If `t&lowbar;INDEX` is not the index of the currently active alternative, throw an exception of type `bad&lowbar;variant&lowbar;access`&period; `t&lowbar;INDEX` shall be a valid index for the variant type of `obj`&period;
| xref:bsl/get-0e3.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get-0e6.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get-0ea.adoc[`get`]
| Return a reference to the alternative object with type (template parameter) `t&lowbar;TYPE` in the specified `obj`&period; If `t&lowbar;TYPE` is not the type of the currently active alternative, throw an exception of type `bad&lowbar;variant&lowbar;access`&period; `t&lowbar;TYPE` shall appear exactly once in the variant&apos;s list of alternatives&period;
| xref:bsl/get-0ee.adoc[`get`]
| See the first `get` overload above&period;
| xref:bsl/get_if-06.adoc[`get&lowbar;if`]
| Return a pointer to the alternative object with type (template parameter) `t&lowbar;TYPE` in the specified `obj`, or a null pointer if `obj` itself is a null pointer or if `t&lowbar;TYPE` is not the type of the currently active alternative&period; `t&lowbar;TYPE` shall appear exactly once in the variant&apos;s list of alternatives&period;
| xref:bsl/get_if-09.adoc[`get&lowbar;if`]
| Return a pointer to the alternative object with type (template parameter) `t&lowbar;TYPE` in the specified `obj`, or a null pointer if `obj` itself is a null pointer or if `t&lowbar;TYPE` is not the type of the currently active alternative&period; `t&lowbar;TYPE` shall appear exactly once in the variant&apos;s list of alternatives&period;
| xref:bsl/get_if-0a.adoc[`get&lowbar;if`]
| Return a pointer to the alternative at index `t&lowbar;INDEX`, or null&period;
| xref:bsl/get_if-0d.adoc[`get&lowbar;if`]
| Return a pointer to the alternative object with index (template parameter) `t&lowbar;INDEX` in the specified `obj`, or a null pointer if `obj` itself is a null pointer or if `t&lowbar;INDEX` is not the index of the currently active alternative&period; `t&lowbar;INDEX` shall be a valid alternative index&period;
| xref:bsl/holds_alternative.adoc[`holds&lowbar;alternative`]
| Return `true` if the specified `obj` currently holds the (template parameter) `t&lowbar;TYPE` alternative, and `false` otherwise&period; `t&lowbar;TYPE` shall appear exactly once in the variant&apos;s list of alternatives&period;
| xref:bsl/operator_not_eq-023.adoc[`operator!&equals;`]
| Return `true` if the specified `lhs` and `rhs` have different active alternatives or only one holds an alternative, or if they have the same active alternative and the contained values compare unequal&semi; otherwise, return `false`&period; All alternatives shall support `operator!&equals;`&period;
| xref:bsl/operator_lt-01d.adoc[`operator&lt;`]
| Return `true` if the index of the active alternative in the specified `lhs` is less than that of the specified `rhs`, or if both have the same active alternative and the contained value of `lhs` compares less than that of `rhs`, or if `lhs` is valueless by exception and `rhs` is not&semi; otherwise, return `false`&period; All alternatives shall support `operator&lt;`&period;
| xref:bsl/operator_le-00.adoc[`operator&lt;&equals;`]
| Return `true` if the index of the active alternative in the specified `lhs` is less than that of the specified `rhs`, or if both have the same active alternative and the contained value of `lhs` compares less than or equal to that of `rhs`, or if `lhs` is valueless by exception&semi; otherwise, return `false`&period; All alternatives shall support `operator&lt;&equals;`&period;
| xref:bsl/operator_3way-09.adoc[`operator&lt;&equals;&gt;`]
| If `lhs` and `rhs` are not valueless by exception and hold the same alternative `i`, return `get(lhs) &lt;&equals;&gt; get(rhs)` &period; If `lhs` and `rhs` are not valueless by exception and hold the aalternatives `i` and `j` respectively, return `i&lt;&equals;&gt;j`&period; Return `strong&lowbar;ordering&colon;&colon;equal` if both variants are valueless by exception&period; Return `strong&lowbar;ordering&colon;&colon;less` if `lhs` is valueless by exception&period; Return `strong&lowbar;ordering&colon;&colon;greater` if `rhs` is valueless by exception&period;
| xref:bsl/operator_eq-058.adoc[`operator&equals;&equals;`]
| Return `true` if the specified `lhs` and `rhs` are both valueless by exception or if they have the same active alternative and their contained values compare equal&semi; otherwise, return `false`&period; All alternatives shall support `operator&equals;&equals;`&period;
| xref:bsl/operator_gt-014.adoc[`operator&gt;`]
| Return `true` if the index of the active alternative in the specified `lhs` is greater than that of the specified `rhs`, or if both have the same active alternative and the contained value of `lhs` compares greater than that of `rhs`, or if `rhs` is valueless by exception and `lhs` is not&semi; otherwise, return `false`&period; All alternatives shall support `operator&gt;`&period;
| xref:bsl/operator_ge-07a.adoc[`operator&gt;&equals;`]
| Return `true` if the index of the active alternative in the specified `lhs` is greater than that of the specified `rhs`, or if both have the same active alternative and the contained value of `lhs` compares greater than or equal to that of `rhs`, or if `rhs` is valueless by exception&semi; otherwise, return `false`&period; All alternatives shall support `operator&gt;&equals;`&period;
| xref:bsl/swap-0f5.adoc[`swap`]
| Efficiently exchange the values of the specified `lhs` and `rhs` objects&period; This method provides the no&hyphen;throw guarantee if the two variant objects being swapped have the same active alternative and that alternative provides that guarantee&semi; otherwise, this method provides the basic guarantee&period; If `lhs` and `rhs` do not contain the same alternative or they have unequal allocators, and an exception is thrown during the swap, either or both variant objects may be left in a valueless state or with an alternative in a moved&hyphen;from state&period; All alternatives shall be move constructible and swappable&period; For simplicity of implementation, this function differs from the standard in the following &colon; &ast; constraints are not implemented &ast; constexpr is not implemented
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
