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

Allocator&hyphen;aware nullable wrapper for an object of type `t&lowbar;TYPE`&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;optional&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;TYPE&gt;
class optional
    : public xref:BloombergLP/bslstl/Optional_Base-05.adoc[BloombergLP::bslstl::Optional&lowbar;Base&lt;t&lowbar;TYPE&gt;]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bslstl/Optional_Base-05.adoc[BloombergLP::bslstl::Optional&lowbar;Base&lt;t&lowbar;TYPE&gt;]`
| Component&hyphen;private class template implementing `bsl&colon;&colon;optional`&period;
|===

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslstl/Optional_Base-05/allocator_type.adoc[`allocator&lowbar;type`] 
| This `typedef` is an alias to `bsl&colon;&colon;allocator&lt;char&gt;`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/value_type.adoc[`value&lowbar;type`] 
| Alias for the managed object type of this optional&period;
|===


== 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&equals;`] 
| Assignment operators
| xref:bsl/optional-072/and_then-08d.adoc[`and&lowbar;then`] 
| `and&lowbar;then` overloads
| xref:BloombergLP/bslstl/Optional_Base-05/emplace-02.adoc[`emplace`] 
| Destroy any contained value and construct a new one in place&period;
| xref:BloombergLP/bslstl/Optional_Base-05/get_allocator.adoc[`get&lowbar;allocator`] 
| Return allocator used for construction of `value&lowbar;type`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/has_value.adoc[`has&lowbar;value`] 
| Return `false` if this object is disengaged, and `true` otherwise&period;
| xref:BloombergLP/bslstl/Optional_Base-05/operator_star-0b.adoc[`operator&ast;`] 
| Dereference operators
| xref:BloombergLP/bslstl/Optional_Base-05/operator_ptr-0a.adoc[`operator&hyphen;&gt;`] 
| Member access operators
| xref:bsl/optional-072/or_else-09.adoc[`or&lowbar;else`] 
| Return this optional if engaged&semi; otherwise invoke `func`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/reset.adoc[`reset`] 
| Reset this object to the default constructed state (i&period;e&period;, to a disengaged state)&period;
| xref:BloombergLP/bslstl/Optional_Base-05/swap.adoc[`swap`] 
| Exchange the values of two optionals&period;
| 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&lowbar;or`] 
| Return the contained value, or a converted fallback if disengaged&period;
| xref:BloombergLP/bslstl/Optional_Base-05/2conversion-076.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;Optional&lowbar;Base, IsBitwiseCopyable, BloombergLP&colon;&colon;bslmf&colon;&colon;IsBitwiseCopyable&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;IsBitwiseCopyable`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/2conversion-04.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;Optional&lowbar;Base, IsBitwiseMoveable, BloombergLP&colon;&colon;bslmf&colon;&colon;IsBitwiseMoveable&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;IsBitwiseMoveable`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/2conversion-0a.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;Optional&lowbar;Base, UsesAllocatorArgT&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;UsesAllocatorArgT`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/2conversion-0b.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;Optional&lowbar;Base, UsesBslmaAllocator&gt;`] 
| Nested trait declaration for `bslma&colon;&colon;UsesBslmaAllocator`&period;
| xref:bsl/optional-072/2conversion-0af.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;optional, IsBitwiseCopyable, BloombergLP&colon;&colon;bslmf&colon;&colon;IsBitwiseCopyable&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;IsBitwiseCopyable`&period;
| xref:bsl/optional-072/2conversion-0a1.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;optional, IsBitwiseMoveable, BloombergLP&colon;&colon;bslmf&colon;&colon;IsBitwiseMoveable&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;IsBitwiseMoveable`&period;
| xref:bsl/optional-072/2conversion-0d.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;optional, UsesAllocatorArgT, BloombergLP&colon;&colon;bslma&colon;&colon;UsesBslmaAllocator&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;UsesAllocatorArgT`&period;
| xref:bsl/optional-072/2conversion-05.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;optional, UsesBslmaAllocator, BloombergLP&colon;&colon;bslma&colon;&colon;UsesBslmaAllocator&lt;t&lowbar;TYPE&gt;&colon;&colon;value&gt;`] 
| Nested trait declaration for `bslma&colon;&colon;UsesBslmaAllocator`&period;
| xref:BloombergLP/bslstl/Optional_Base-05/2conversion-071.adoc[`operator bool`] 
| Return `false` if this object is disengaged, and `true` otherwise&period;
|===


== Protected Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslstl/Optional_Base-05/AllocType.adoc[`AllocType`] 
| This `typedef` is an alias to `allocator&lowbar;type`&period;
|===


== 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&period;
| xref:BloombergLP/bslstl/Optional_Base-05/dereferenceRaw-049.adoc[`dereferenceRaw`] 
| Return a reference to the contained value without checking engagement&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/optional-0d.adoc[`optional&lt;t&lowbar;TYPE&gt;`] 
| Deduce the specified type `t&lowbar;TYPE` from the corresponding type supplied to the constructor of `optional`&period;
| xref:bsl/optional-0b.adoc[`optional&lt;t&lowbar;TYPE&gt;`] 
| Deduce `t&lowbar;TYPE` for an allocator&hyphen;aware optional from a value&period;
| xref:bsl/optional-07d.adoc[`optional&lt;t&lowbar;TYPE&gt;`] 
| Deduce `t&lowbar;TYPE` for an allocator&hyphen;aware optional from another optional&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `bsl::optional`
| Allocator&hyphen;aware nullable wrapper for an object of type `t&lowbar;TYPE`&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/PrintTo-0f.adoc[`PrintTo`]
| Write the specified `value` to the specified `&ast;stream`, surrounded by double quotes&period;
| xref:bsl/make_optional-00.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/make_optional-01.adoc[`make&lowbar;optional`]
| Return an `optional` object containing a value&hyphen;initialized `t&lowbar;TYPE` object&period;
| xref:bsl/make_optional-03.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/make_optional-04.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/make_optional-06.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/make_optional-0a.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/make_optional-0e.adoc[`make&lowbar;optional`]
| Return an `optional` containing a value constructed from the arguments&period;
| xref:bsl/operator_not_eq-0c3.adoc[`operator!&equals;`]
| Return whether the operands do not have the same value&period;
| xref:bsl/operator_not_eq-0cf.adoc[`operator!&equals;`]
| Return whether the operands do not have the same value&period;
| xref:bsl/operator_not_eq-0e.adoc[`operator!&equals;`]
| Return whether the operands do not have the same value&period;
| xref:bsl/operator_lt-00.adoc[`operator&lt;`]
| Return whether the left&hyphen;hand operand is ordered before the right&period;
| xref:bsl/operator_lt-010.adoc[`operator&lt;`]
| Return whether the left&hyphen;hand operand is ordered before the right&period;
| xref:bsl/operator_lt-0b.adoc[`operator&lt;`]
| Return whether the left&hyphen;hand operand is ordered before the right&period;
| xref:bsl/operator_le-03.adoc[`operator&lt;&equals;`]
| Return whether the left&hyphen;hand operand is before or equal to the right&period;
| xref:bsl/operator_le-04.adoc[`operator&lt;&equals;`]
| Return whether the left&hyphen;hand operand is before or equal to the right&period;
| xref:bsl/operator_le-0c.adoc[`operator&lt;&equals;`]
| Return whether the left&hyphen;hand operand is before or equal to the right&period;
| xref:bsl/operator_3way-00.adoc[`operator&lt;&equals;&gt;`]
| Perform a three&hyphen;way comparison of the operands&period;
| xref:bsl/operator_3way-070.adoc[`operator&lt;&equals;&gt;`]
| Perform a three&hyphen;way comparison of the operands&period;
| xref:bsl/operator_3way-0a.adoc[`operator&lt;&equals;&gt;`]
| Perform a three&hyphen;way comparison of the operands&period;
| xref:bsl/operator_3way-0d1.adoc[`operator&lt;&equals;&gt;`]
| Perform a three&hyphen;way comparison of the operands&period;
| xref:bsl/operator_eq-02a.adoc[`operator&equals;&equals;`]
| Return whether the operands have the same value&period;
| xref:bsl/operator_eq-097.adoc[`operator&equals;&equals;`]
| Return whether the operands have the same value&period;
| xref:bsl/operator_eq-09de.adoc[`operator&equals;&equals;`]
| Compare a `std&colon;&colon;optional` with a `bsl&colon;&colon;optional` for equality&period;
| xref:bsl/operator_eq-0db.adoc[`operator&equals;&equals;`]
| Return whether the operands have the same value&period;
| xref:bsl/operator_gt-04.adoc[`operator&gt;`]
| Return whether the left&hyphen;hand operand is ordered after the right&period;
| xref:bsl/operator_gt-07.adoc[`operator&gt;`]
| Return whether the left&hyphen;hand operand is ordered after the right&period;
| xref:bsl/operator_gt-0bc.adoc[`operator&gt;`]
| Return whether the left&hyphen;hand operand is ordered after the right&period;
| xref:bsl/operator_ge-05.adoc[`operator&gt;&equals;`]
| Return whether the left&hyphen;hand operand is after or equal to the right&period;
| xref:bsl/operator_ge-06.adoc[`operator&gt;&equals;`]
| Return whether the left&hyphen;hand operand is after or equal to the right&period;
| xref:bsl/operator_ge-088.adoc[`operator&gt;&equals;`]
| Return whether the left&hyphen;hand operand is after or equal to the right&period;
| xref:bsl/swap-00c.adoc[`swap`]
| Exchange the values of two optionals&period;
| xref:bsl/swap-04d.adoc[`swap`]
| Exchange the values of two optionals&period;
| xref:bsl/swap-0f3.adoc[`swap`]
| Exchange the values of two optionals&period;
| xref:BloombergLP/bdlb/nullableValue_acceptsBslOptional.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;nullableValue&lowbar;acceptsBslOptional`]
| Component&hyphen;private constraint helper for `bsl&colon;&colon;optional` conversion&period;
| xref:BloombergLP/bdlb/operator_not_eq-07b.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator!&equals;`]
| Return `true` if the specified nullable objects do not have the same value&period;
| xref:BloombergLP/bdlb/operator_not_eq-0a1.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator!&equals;`]
| Return `true` if the specified nullable objects do not have the same value&period;
| xref:BloombergLP/bdlb/operator_lt-07.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&lt;`]
| Return `true` if `lhs` is ordered before `rhs`, and `false` otherwise&period;
| xref:BloombergLP/bdlb/operator_lt-0b.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&lt;`]
| Return whether the left&hyphen;hand operand is ordered before the right&period;
| xref:BloombergLP/bdlb/operator_le-041.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&lt;&equals;`]
| Return whether the left&hyphen;hand operand is before or equal to the right&period;
| xref:BloombergLP/bdlb/operator_le-06b.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&lt;&equals;`]
| Return `true` if `lhs` is ordered before `rhs` or they are equal&period;
| xref:BloombergLP/bdlb/operator_eq-047.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&equals;&equals;`]
| Return `true` if the specified nullable objects have the same value&period;
| xref:BloombergLP/bdlb/operator_eq-052.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&equals;&equals;`]
| Return `true` if the specified nullable objects have the same value, and `false` otherwise&period;
| xref:BloombergLP/bdlb/operator_gt-00.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&gt;`]
| Return `true` if `lhs` is ordered after `rhs`, and `false` otherwise&period;
| xref:BloombergLP/bdlb/operator_gt-04b.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&gt;`]
| Return whether the left&hyphen;hand operand is ordered after the right&period;
| xref:BloombergLP/bdlb/operator_ge-01d1.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&gt;&equals;`]
| Return whether the left&hyphen;hand operand is after or equal to the right&period;
| xref:BloombergLP/bdlb/operator_ge-087.adoc[`&colon;&colon;BloombergLP&colon;&colon;bdlb&colon;&colon;operator&gt;&equals;`]
| Return `true` if `lhs` is ordered after `rhs` or they are equal&period;
| xref:BloombergLP/bslstl/optional_acceptsBslOptional.adoc[`&colon;&colon;BloombergLP&colon;&colon;bslstl&colon;&colon;optional&lowbar;acceptsBslOptional`]
| Component&hyphen;private constraint helper for `Optional&lowbar;DerivedFromBslOptional`&period;
|===

== Derived Classes

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlb/NullableValue.adoc[`NullableValue`] 
| Value&hyphen;semantic wrapper that adds a null state to `TYPE`&period;
|===


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