[#bsl-optional-072] = xref:bsl.adoc[bsl]::optional :relfileprefix: ../ :mrdocs: Allocator‐aware nullable wrapper for an object of type `t_TYPE`. == Synopsis Declared in `<bslstl_optional.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_TYPE> class optional : public xref:BloombergLP/bslstl/Optional_Base-05.adoc[BloombergLP::bslstl::Optional_Base<t_TYPE>] ---- == Base Classes [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bslstl/Optional_Base-05.adoc[BloombergLP::bslstl::Optional_Base<t_TYPE>]` | Component‐private class template implementing `bsl::optional`. |=== == 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`] | Alias for the managed object type of this optional. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/optional-072/2constructor-043.adoc[`optional`] [.small]#[constructor]# | Constructors | xref:bsl/optional-072/operator_assign-01.adoc[`operator=`] | Assignment operators | xref:bsl/optional-072/and_then-08d.adoc[`and_then`] | `and_then` overloads | xref:BloombergLP/bslstl/Optional_Base-05/emplace-02.adoc[`emplace`] | Destroy any contained value and construct a new one in place. | 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:bsl/optional-072/or_else-09.adoc[`or_else`] | Return this optional if engaged; otherwise invoke `func`. | 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`] | Exchange the values of two optionals. | xref:bsl/optional-072/transform-09d.adoc[`transform`] | `transform` overloads | xref:BloombergLP/bslstl/Optional_Base-05/value-07a.adoc[`value`] | `value` overloads | xref:BloombergLP/bslstl/Optional_Base-05/value_or-07.adoc[`value_or`] | Return the contained value, or a converted fallback if disengaged. | 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:bsl/optional-072/2conversion-0af.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<optional, IsBitwiseCopyable, BloombergLP::bslmf::IsBitwiseCopyable<t_TYPE>::value>`] | Nested trait declaration for `bslmf::IsBitwiseCopyable`. | xref:bsl/optional-072/2conversion-0a1.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<optional, IsBitwiseMoveable, BloombergLP::bslmf::IsBitwiseMoveable<t_TYPE>::value>`] | Nested trait declaration for `bslmf::IsBitwiseMoveable`. | xref:bsl/optional-072/2conversion-0d.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<optional, UsesAllocatorArgT, BloombergLP::bslma::UsesBslmaAllocator<t_TYPE>::value>`] | Nested trait declaration for `bslmf::UsesAllocatorArgT`. | xref:bsl/optional-072/2conversion-05.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<optional, UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator<t_TYPE>::value>`] | 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/assignOrEmplace.adoc[`assignOrEmplace`] | Assign or emplace a value into this optional. | xref:BloombergLP/bslstl/Optional_Base-05/dereferenceRaw-049.adoc[`dereferenceRaw`] | Return a reference to the contained value without checking engagement. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:bsl/optional-0d.adoc[`optional<t_TYPE>`] | Deduce the specified type `t_TYPE` from the corresponding type supplied to the constructor of `optional`. | xref:bsl/optional-0b.adoc[`optional<t_TYPE>`] | Deduce `t_TYPE` for an allocator‐aware optional from a value. | xref:bsl/optional-07d.adoc[`optional<t_TYPE>`] | Deduce `t_TYPE` for an allocator‐aware optional from another optional. |=== == Friends [cols="1,4"] |=== | Name| Description | `bsl::optional` | Allocator‐aware nullable wrapper for an object of type `t_TYPE`. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/PrintTo-0f.adoc[`PrintTo`] | Write the specified `value` to the specified `*stream`, surrounded by double quotes. | xref:bsl/make_optional-00.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/make_optional-01.adoc[`make_optional`] | Return an `optional` object containing a value‐initialized `t_TYPE` object. | xref:bsl/make_optional-03.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/make_optional-04.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/make_optional-06.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/make_optional-0a.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/make_optional-0e.adoc[`make_optional`] | Return an `optional` containing a value constructed from the arguments. | xref:bsl/operator_not_eq-0c3.adoc[`operator!=`] | Return whether the operands do not have the same value. | xref:bsl/operator_not_eq-0cf.adoc[`operator!=`] | Return whether the operands do not have the same value. | xref:bsl/operator_not_eq-0e.adoc[`operator!=`] | Return whether the operands do not have the same value. | xref:bsl/operator_lt-00.adoc[`operator<`] | Return whether the left‐hand operand is ordered before the right. | xref:bsl/operator_lt-010.adoc[`operator<`] | Return whether the left‐hand operand is ordered before the right. | xref:bsl/operator_lt-0b.adoc[`operator<`] | Return whether the left‐hand operand is ordered before the right. | xref:bsl/operator_le-03.adoc[`operator<=`] | Return whether the left‐hand operand is before or equal to the right. | xref:bsl/operator_le-04.adoc[`operator<=`] | Return whether the left‐hand operand is before or equal to the right. | xref:bsl/operator_le-0c.adoc[`operator<=`] | Return whether the left‐hand operand is before or equal to the right. | xref:bsl/operator_3way-00.adoc[`operator<=>`] | Perform a three‐way comparison of the operands. | xref:bsl/operator_3way-070.adoc[`operator<=>`] | Perform a three‐way comparison of the operands. | xref:bsl/operator_3way-0a.adoc[`operator<=>`] | Perform a three‐way comparison of the operands. | xref:bsl/operator_3way-0d1.adoc[`operator<=>`] | Perform a three‐way comparison of the operands. | xref:bsl/operator_eq-02a.adoc[`operator==`] | Return whether the operands have the same value. | xref:bsl/operator_eq-097.adoc[`operator==`] | Return whether the operands have the same value. | xref:bsl/operator_eq-09de.adoc[`operator==`] | Compare a `std::optional` with a `bsl::optional` for equality. | xref:bsl/operator_eq-0db.adoc[`operator==`] | Return whether the operands have the same value. | xref:bsl/operator_gt-04.adoc[`operator>`] | Return whether the left‐hand operand is ordered after the right. | xref:bsl/operator_gt-07.adoc[`operator>`] | Return whether the left‐hand operand is ordered after the right. | xref:bsl/operator_gt-0bc.adoc[`operator>`] | Return whether the left‐hand operand is ordered after the right. | xref:bsl/operator_ge-05.adoc[`operator>=`] | Return whether the left‐hand operand is after or equal to the right. | xref:bsl/operator_ge-06.adoc[`operator>=`] | Return whether the left‐hand operand is after or equal to the right. | xref:bsl/operator_ge-088.adoc[`operator>=`] | Return whether the left‐hand operand is after or equal to the right. | xref:bsl/swap-00c.adoc[`swap`] | Exchange the values of two optionals. | xref:bsl/swap-04d.adoc[`swap`] | Exchange the values of two optionals. | xref:bsl/swap-0f3.adoc[`swap`] | Exchange the values of two optionals. | xref:BloombergLP/bdlb/nullableValue_acceptsBslOptional.adoc[`::BloombergLP::bdlb::nullableValue_acceptsBslOptional`] | Component‐private constraint helper for `bsl::optional` conversion. | xref:BloombergLP/bdlb/operator_not_eq-07b.adoc[`::BloombergLP::bdlb::operator!=`] | Return `true` if the specified nullable objects do not have the same value. | xref:BloombergLP/bdlb/operator_not_eq-0a1.adoc[`::BloombergLP::bdlb::operator!=`] | Return `true` if the specified nullable objects do not have the same value. | xref:BloombergLP/bdlb/operator_lt-07.adoc[`::BloombergLP::bdlb::operator<`] | Return `true` if `lhs` is ordered before `rhs`, and `false` otherwise. | xref:BloombergLP/bdlb/operator_lt-0b.adoc[`::BloombergLP::bdlb::operator<`] | Return whether the left‐hand operand is ordered before the right. | xref:BloombergLP/bdlb/operator_le-041.adoc[`::BloombergLP::bdlb::operator<=`] | Return whether the left‐hand operand is before or equal to the right. | xref:BloombergLP/bdlb/operator_le-06b.adoc[`::BloombergLP::bdlb::operator<=`] | Return `true` if `lhs` is ordered before `rhs` or they are equal. | xref:BloombergLP/bdlb/operator_eq-047.adoc[`::BloombergLP::bdlb::operator==`] | Return `true` if the specified nullable objects have the same value. | xref:BloombergLP/bdlb/operator_eq-052.adoc[`::BloombergLP::bdlb::operator==`] | Return `true` if the specified nullable objects have the same value, and `false` otherwise. | xref:BloombergLP/bdlb/operator_gt-00.adoc[`::BloombergLP::bdlb::operator>`] | Return `true` if `lhs` is ordered after `rhs`, and `false` otherwise. | xref:BloombergLP/bdlb/operator_gt-04b.adoc[`::BloombergLP::bdlb::operator>`] | Return whether the left‐hand operand is ordered after the right. | xref:BloombergLP/bdlb/operator_ge-01d1.adoc[`::BloombergLP::bdlb::operator>=`] | Return whether the left‐hand operand is after or equal to the right. | xref:BloombergLP/bdlb/operator_ge-087.adoc[`::BloombergLP::bdlb::operator>=`] | Return `true` if `lhs` is ordered after `rhs` or they are equal. | xref:BloombergLP/bslstl/optional_acceptsBslOptional.adoc[`::BloombergLP::bslstl::optional_acceptsBslOptional`] | Component‐private constraint helper for `Optional_DerivedFromBslOptional`. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlb/NullableValue.adoc[`NullableValue`] | Value‐semantic wrapper that adds a null state to `TYPE`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#