Synopsis

Declared in <bslstl_variant.h>

template<
    class t_HEAD,
    class... t_TAIL>
class variant;

Type Aliases

Name

Description

allocator_type

Type alias to the allocator type used by variant.

Member Functions

Name

Description

variant [constructor]

Constructors

operator=

Assignment operators

emplace

emplace overloads

get_allocator

Return a copy of this object's allocator. At least one alternative of this variant object shall be allocator‐aware; in C++03, due to language limitations, this method can be called even if no alternative is allocator‐aware, but returns a non‐allocator type in that case.

index

Return the index of the alternative currently managed by this variant object, or bsl::variant_npos if this object is valueless by exception. This method differs from the standard in the following way: * 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.

swap

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no‐throw exception‐safety guarantee if the two swapped objects contain the same alternative and if that alternative t_TYPE provides that guarantee. If *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‐from state. The behavior is undefined unless *this has the same allocator as other. All alternatives shall be move constructible and swappable. For simplicity of implementation, this method differs from the standard in the following ways: * constexpr is not implemented * noexcept specification is not implemented

valueless_by_exception

Return false if there is an alternative object currently managed by this variant object, and true otherwise. 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. This method differs from the standard in the following way: * 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.

operator BloombergLP::bslmf::NestedTraitDeclaration<variant, IsBitwiseMoveable, (BloombergLP::bslstl::Variant_IsBitwiseMoveableAll<t_HEAD, t_TAIL...>::value)>

Nested trait declaration for IsBitwiseMoveable.

operator BloombergLP::bslmf::NestedTraitDeclaration<variant, UsesAllocatorArgT, (BloombergLP::bslstl::Variant_UsesBslmaAllocatorAny<t_HEAD, t_TAIL...>::value)>

Nested trait declaration for UsesAllocatorArgT.

operator BloombergLP::bslmf::NestedTraitDeclaration<variant, UsesBslmaAllocator, (BloombergLP::bslstl::Variant_UsesBslmaAllocatorAny<t_HEAD, t_TAIL...>::value)>

Nested trait declaration for UsesBslmaAllocator.

Friends

Name

Description

BloombergLP::bslstl::Variant_Base

This component‐private struct defines the data representation of bsl::variant and contains the implementations of its special member functions (which must be defaulted in bsl::variant itself). This class also contains implementations of additional constructors and methods needed for the correct functionality of the variant class hierarchy.

Non-Member Functions

Name

Description

get

See the first get overload above.

get

See the first get overload above.

get

See the first get overload above.

get

Return a reference to the alternative object at index (template parameter) t_INDEX in the specified obj. If t_INDEX is not the index of the currently active alternative, throw an exception of type bad_variant_access. t_INDEX shall be a valid index for the variant type of obj.

get

See the first get overload above.

get

See the first get overload above.

get

Return a reference to the alternative object with type (template parameter) t_TYPE in the specified obj. If t_TYPE is not the type of the currently active alternative, throw an exception of type bad_variant_access. t_TYPE shall appear exactly once in the variant's list of alternatives.

get

See the first get overload above.

get_if

Return a pointer to the alternative object with type (template parameter) t_TYPE in the specified obj, or a null pointer if obj itself is a null pointer or if t_TYPE is not the type of the currently active alternative. t_TYPE shall appear exactly once in the variant's list of alternatives.

get_if

Return a pointer to the alternative object with type (template parameter) t_TYPE in the specified obj, or a null pointer if obj itself is a null pointer or if t_TYPE is not the type of the currently active alternative. t_TYPE shall appear exactly once in the variant's list of alternatives.

get_if

Return a pointer to the alternative at index t_INDEX, or null.

get_if

Return a pointer to the alternative object with index (template parameter) t_INDEX in the specified obj, or a null pointer if obj itself is a null pointer or if t_INDEX is not the index of the currently active alternative. t_INDEX shall be a valid alternative index.

holds_alternative

Return true if the specified obj currently holds the (template parameter) t_TYPE alternative, and false otherwise. t_TYPE shall appear exactly once in the variant's list of alternatives.

operator!=

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; otherwise, return false. All alternatives shall support operator!=.

operator<

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; otherwise, return false. All alternatives shall support operator<.

operator<=

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; otherwise, return false. All alternatives shall support operator<=.

operator<=>

If lhs and rhs are not valueless by exception and hold the same alternative i, return get(lhs) <=> get(rhs) . If lhs and rhs are not valueless by exception and hold the aalternatives i and j respectively, return i<=>j. Return strong_ordering::equal if both variants are valueless by exception. Return strong_ordering::less if lhs is valueless by exception. Return strong_ordering::greater if rhs is valueless by exception.

operator==

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; otherwise, return false. All alternatives shall support operator==.

operator>

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; otherwise, return false. All alternatives shall support operator>.

operator>=

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; otherwise, return false. All alternatives shall support operator>=.

swap

Efficiently exchange the values of the specified lhs and rhs objects. This method provides the no‐throw guarantee if the two variant objects being swapped have the same active alternative and that alternative provides that guarantee; otherwise, this method provides the basic guarantee. 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‐from state. All alternatives shall be move constructible and swappable. For simplicity of implementation, this function differs from the standard in the following : * constraints are not implemented * constexpr is not implemented

Created with MrDocs