[#BloombergLP-bdlb-Variant] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlb.adoc[bdlb]::Variant :relfileprefix: ../../ :mrdocs: Discriminated union that holds a value of one of up to 20 alternative types. == Synopsis Declared in `<bdlb_variant.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class... TYPES> class Variant : public xref:BloombergLP/bdlb/VariantImp.adoc[VariantImp<bslmf::TypeList<TYPES...>::ListType>] ---- == Description This class provides a "variant" type, i.e., a type capable of storing values from a list of template parameter types. Note that if the number `N` of types is smaller than 20, unused parameters default to `bslmf::Nil`, but it is more economical to use `VariantN`, which accepts exactly `N` template arguments, as this leads to shorter symbols and debug string information. == Base Classes [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bdlb/VariantImp.adoc[VariantImp<bslmf::TypeList<TYPES...>::ListType>]` | This class provides the implementation of `Variant` (except for the creators) given a list of template parameter `TYPES`. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlb/Variant/2constructor-035.adoc[`Variant`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlb/Variant/operator_assign-0e.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bdlb/Variant/apply.adoc[`apply`] | `apply` overloads | xref:BloombergLP/bdlb/Variant/applyRaw.adoc[`applyRaw`] | `applyRaw` overloads | xref:BloombergLP/bdlb/Variant/assign.adoc[`assign`] | Assign the specified `TYPE` `value` to this object. | xref:BloombergLP/bdlb/VariantImp/assignTo.adoc[`assignTo`] | Assign `value` converted to `TYPE` to this object. | xref:BloombergLP/bdlb/VariantImp/bdexStreamIn.adoc[`bdexStreamIn`] | DEPRECATED: Do not use. | xref:BloombergLP/bdlb/VariantImp/bdexStreamOut.adoc[`bdexStreamOut`] | DEPRECATED: Do not use. | xref:BloombergLP/bdlb/VariantImp/createInPlace.adoc[`createInPlace`] | Emplace a `TYPE` instance constructed from `arguments`. | xref:BloombergLP/bdlb/VariantImp/is.adoc[`is`] | Return whether this variant currently holds a `TYPE` value. | xref:BloombergLP/bdlb/VariantImp/isUnset.adoc[`isUnset`] | Return whether this variant currently holds no value. | xref:BloombergLP/bdlb/VariantImp/maxSupportedBdexVersion.adoc[`maxSupportedBdexVersion`] | DEPRECATED: Do not use. | xref:BloombergLP/bdlb/VariantImp/print.adoc[`print`] | Format this object to the specified output `stream`. | xref:BloombergLP/bdlb/VariantImp/reset.adoc[`reset`] | Destroy the current value held by this variant (if any), and reset this variant to the unset state. | xref:BloombergLP/bdlb/VariantImp/swap.adoc[`swap`] | Swap the value of this object with `other`. | xref:BloombergLP/bdlb/Variant/the.adoc[`the`] | `the` overloads | xref:BloombergLP/bdlb/VariantImp/typeIndex.adoc[`typeIndex`] | Return the 1‐based index of the held type, or 0 if unset. | xref:BloombergLP/bdlb/VariantImp/typeInfo.adoc[`typeInfo`] | Return `typeid(void)`. | xref:BloombergLP/bdlb/Variant/2conversion-09.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Variant, HasPrintMethod>`] | Nested trait declaration for `bdlb::HasPrintMethod`. | xref:BloombergLP/bdlb/Variant/2conversion-0a.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Variant, IsBitwiseCopyable, Traits::k_VARIANT_IS_BITWISE_COPYABLE>`] | Nested trait declaration for `bslmf::IsBitwiseCopyable`. | xref:BloombergLP/bdlb/Variant/2conversion-058.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Variant, IsBitwiseMoveable, Traits::k_VARIANT_IS_BITWISE_MOVEABLE>`] | Nested trait declaration for `bslmf::IsBitwiseMoveable`. | xref:BloombergLP/bdlb/Variant/2conversion-050.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Variant, UsesBslmaAllocator, Traits::k_VARIANT_USES_BSLMA_ALLOCATOR>`] | Nested trait declaration for `bslma::UsesBslmaAllocator`. | xref:BloombergLP/bdlb/VariantImp/2conversion-0e.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<VariantImp, HasPrintMethod>`] | Nested trait declaration for `bdlb::HasPrintMethod`. | xref:BloombergLP/bdlb/VariantImp/2conversion-02.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<VariantImp, IsBitwiseCopyable, Traits::k_VARIANT_IS_BITWISE_COPYABLE>`] | Nested trait declaration for `bslmf::IsBitwiseCopyable`. | xref:BloombergLP/bdlb/VariantImp/2conversion-05.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<VariantImp, IsBitwiseMoveable, Traits::k_VARIANT_IS_BITWISE_MOVEABLE>`] | Nested trait declaration for `bslmf::IsBitwiseMoveable`. | xref:BloombergLP/bdlb/VariantImp/2conversion-04.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<VariantImp, UsesBslmaAllocator, Traits::k_VARIANT_USES_BSLMA_ALLOCATOR>`] | Nested trait declaration for `bslma::UsesBslmaAllocator`. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlb/operator_not_eq-045.adoc[`operator!=`] | Return whether `lhs` and `rhs` do not have the same value. | xref:BloombergLP/bdlb/operator_eq-0101.adoc[`operator==`] | Grant the equality comparison operator access to this class's private members. | xref:BloombergLP/bdlb/operator_eq-0fc.adoc[`operator==`] | Return whether `lhs` and `rhs` have the same value. | xref:BloombergLP/bdlb/swap-04.adoc[`swap`] | Swap the values of the specified `a` and `b` objects. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#