[#BloombergLP-bslstl-Optional_Base-05] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::Optional_Base :relfileprefix: ../../ :mrdocs: This component‐private class template implements the functionality of `bsl::optional`. The primary template is instantiated when `TYPE` is allocator‐aware, and holds the allocator that is used to create the stored object. == Synopsis Declared in `<bslstl_optional.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class t_TYPE, bool t_USES_BSLMA_ALLOC = BloombergLP::bslma::UsesBslmaAllocator<t_TYPE>::value> class Optional_Base; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Optional_Base-05/allocator_type.adoc[`allocator_type`] | This `typedef` is an alias to `bsl::allocator<char>`. | xref:BloombergLP/bslstl/Optional_Base-05/value_type.adoc[`value_type`] | `value_type` is an alias for the underlying `TYPE` upon which this template class is instantiated, and represents the type of the managed object. The name is chosen so it is compatible with the `std::optional` implementation. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Optional_Base-05/operator_assign-09.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bslstl/Optional_Base-05/emplace-02.adoc[`emplace`] | `emplace` overloads | xref:BloombergLP/bslstl/Optional_Base-05/get_allocator.adoc[`get_allocator`] | Return allocator used for construction of `value_type`. | xref:BloombergLP/bslstl/Optional_Base-05/has_value.adoc[`has_value`] | Return `false` if this object is disengaged, and `true` otherwise. | xref:BloombergLP/bslstl/Optional_Base-05/operator_star-0b.adoc[`operator*`] | Dereference operators | xref:BloombergLP/bslstl/Optional_Base-05/operator_ptr-0a.adoc[`operator‐>`] | Member access operators | xref:BloombergLP/bslstl/Optional_Base-05/reset.adoc[`reset`] | Reset this object to the default constructed state (i.e., to a disengaged state). | xref:BloombergLP/bslstl/Optional_Base-05/swap.adoc[`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 template parameter `t_TYPE` provides that guarantee and the result of the `hasValue` method for the two objects being swapped is the same. The behavior is undefined unless this object was created with the same allocator as `other`. | xref:BloombergLP/bslstl/Optional_Base-05/value-07a.adoc[`value`] | `value` overloads | xref:BloombergLP/bslstl/Optional_Base-05/value_or-07.adoc[`value_or`] | `value_or` overloads | xref:BloombergLP/bslstl/Optional_Base-05/2conversion-076.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, IsBitwiseCopyable, BloombergLP::bslmf::IsBitwiseCopyable<t_TYPE>::value>`] | Nested trait declaration for `bslmf::IsBitwiseCopyable`. | xref:BloombergLP/bslstl/Optional_Base-05/2conversion-04.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, IsBitwiseMoveable, BloombergLP::bslmf::IsBitwiseMoveable<t_TYPE>::value>`] | Nested trait declaration for `bslmf::IsBitwiseMoveable`. | xref:BloombergLP/bslstl/Optional_Base-05/2conversion-0a.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, UsesAllocatorArgT>`] | Nested trait declaration for `bslmf::UsesAllocatorArgT`. | xref:BloombergLP/bslstl/Optional_Base-05/2conversion-0b.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Optional_Base, UsesBslmaAllocator>`] | Nested trait declaration for `bslma::UsesBslmaAllocator`. | xref:BloombergLP/bslstl/Optional_Base-05/2conversion-071.adoc[`operator bool`] | Return `false` if this object is disengaged, and `true` otherwise. |=== == Protected Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Optional_Base-05/AllocType.adoc[`AllocType`] | This `typedef` is an alias to `allocator_type`. |=== == Protected Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Optional_Base-05/2constructor-0f.adoc[`Optional_Base`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bslstl/Optional_Base-05/assignOrEmplace.adoc[`assignOrEmplace`] | If `*this` holds an object, assign to that object the value of the specified `rhs`, converted to `t_TYPE`. Otherwise, construct a held object from `rhs`, converted to `t_TYPE`. The allocators of `*this` and `rhs` remain unchanged. | xref:BloombergLP/bslstl/Optional_Base-05/dereferenceRaw-049.adoc[`dereferenceRaw`] | `dereferenceRaw` overloads |=== == Specializations [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslstl/Optional_Base-08.adoc[`Optional_Base<t_TYPE, false>`] | Specialization of `Optional_Base` for `value_type` that is not allocator‐aware when `std::optional` is available. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:bsl/optional-072.adoc[`optional`] | |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#