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

Type&hyphen;safe discriminated union of alternative types&period;

== 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;
| xref:bsl/variant/index.adoc[`index`] 
| Return the index of the currently managed alternative&period;
| xref:bsl/variant/swap.adoc[`swap`] 
| Efficiently exchange the value of this object with `other`&apos;s value&period;
| xref:bsl/variant/valueless_by_exception.adoc[`valueless&lowbar;by&lowbar;exception`] 
| Return `true` if this object is valueless by exception&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]`
| Define the data representation and special member functions of `bsl&colon;&colon;variant`&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 at index `t&lowbar;INDEX` in `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 of type `t&lowbar;TYPE` in `obj`&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 `t&lowbar;TYPE` alternative in `obj` if active&period;
| xref:bsl/get_if-09.adoc[`get&lowbar;if`]
| Return a pointer to the `t&lowbar;TYPE` alternative in `obj` if active&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 at index `t&lowbar;INDEX` in `obj`, or null&period;
| xref:bsl/holds_alternative.adoc[`holds&lowbar;alternative`]
| Return `true` if `obj` currently holds the `t&lowbar;TYPE` alternative&period;
| xref:bsl/operator_not_eq-023.adoc[`operator!&equals;`]
| Return `true` if `lhs` and `rhs` are not equal&period;
| xref:bsl/operator_lt-01d.adoc[`operator&lt;`]
| Return `true` if `lhs` is less than `rhs`&period;
| xref:bsl/operator_le-00.adoc[`operator&lt;&equals;`]
| Return `true` if `lhs` is less than or equal to `rhs`&period;
| xref:bsl/operator_3way-09.adoc[`operator&lt;&equals;&gt;`]
| Return the three&hyphen;way comparison result of `lhs` and `rhs`&period;
| xref:bsl/operator_eq-058.adoc[`operator&equals;&equals;`]
| Return `true` if `lhs` and `rhs` are equal&period;
| xref:bsl/operator_gt-014.adoc[`operator&gt;`]
| Return `true` if `lhs` is greater than `rhs`&period;
| xref:bsl/operator_ge-07a.adoc[`operator&gt;&equals;`]
| Return `true` if `lhs` is greater than or equal to `rhs`&period;
| xref:bsl/swap-0f5.adoc[`swap`]
| Efficiently exchange the values of the specified `lhs` and `rhs` objects&period;
|===


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