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

Constructors

== Synopses

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

Create a disengaged `optional` object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/optional-072/2constructor-0ae.adoc[optional]() noexcept;
----

[.small]#xref:bsl/optional-072/2constructor-0ae.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072/2constructor-07f.adoc[optional](xref:bsl/optional-072.adoc[optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;] const& original);
----

[.small]#xref:bsl/optional-072/2constructor-07f.adoc[_» more&period;&period;&period;_]#

Construct an `optional` in&hyphen;place from the specified arguments&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-0cb.adoc[optional](xref:bsl/optional-072.adoc[optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;] const& original);
----

[.small]#xref:bsl/optional-072/2constructor-0cb.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/optional-072/2constructor-0d3.adoc[optional](xref:bsl/nullopt_t.adoc[bsl::nullopt&lowbar;t] nullopt) noexcept;
----

[.small]#xref:bsl/optional-072/2constructor-0d3.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()` moved&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072/2constructor-080.adoc[optional](xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&gt;] original);
----

[.small]#xref:bsl/optional-072/2constructor-080.adoc[_» more&period;&period;&period;_]#

Same as the preceding overload&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-004.adoc[optional](xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&gt;] original);
----

[.small]#xref:bsl/optional-072/2constructor-004.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072/2constructor-035.adoc[optional](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt; const& original);
----

[.small]#xref:bsl/optional-072/2constructor-035.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-013.adoc[optional](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt; const& original);
----

[.small]#xref:bsl/optional-072/2constructor-013.adoc[_» more&period;&period;&period;_]#

Create an `optional` object whose contained value is initialized by forwarding from the specified `value`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072/2constructor-0af.adoc[optional](t&lowbar;ANY&lowbar;TYPE&& value);
----

[.small]#xref:bsl/optional-072/2constructor-0af.adoc[_» more&period;&period;&period;_]#

Create an `optional` object whose contained value is initialized by forwarding from the specified `value`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-0c2.adoc[optional](t&lowbar;ANY&lowbar;TYPE&& value);
----

[.small]#xref:bsl/optional-072/2constructor-0c2.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
xref:bsl/optional-072/2constructor-05.adoc[optional](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&& original);
----

[.small]#xref:bsl/optional-072/2constructor-05.adoc[_» more&period;&period;&period;_]#

Explicitly create an `optional` by moving from the specified `std&colon;&colon;optional` `original`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-0f0.adoc[optional](std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&& original);
----

[.small]#xref:bsl/optional-072/2constructor-0f0.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/optional-072/2constructor-0e.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator);
----

[.small]#xref:bsl/optional-072/2constructor-0e.adoc[_» more&period;&period;&period;_]#

Create an `optional` object having the value of the (template parameter) `t&lowbar;TYPE` created in place using the specified `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class&period;&period;&period; t&lowbar;ARGS&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-0c8.adoc[optional](
    std::in&lowbar;place&lowbar;t inPlace,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/optional-072/2constructor-0c8.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/optional-072/2constructor-08f.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:bsl/nullopt_t.adoc[bsl::nullopt&lowbar;t] nullopt);
----

[.small]#xref:bsl/optional-072/2constructor-08f.adoc[_» more&period;&period;&period;_]#

If the specified `original` contains a value, create an `optional` object whose contained value is initialized from `&ast;original`&semi; otherwise, create a&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/optional-072/2constructor-06c.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:bsl/optional-072.adoc[optional] const& original);
----

[.small]#xref:bsl/optional-072/2constructor-06c.adoc[_» more&period;&period;&period;_]#

If the `optional` base class of the specified `original` holds a value, create an `optional` object whose contained value is initialized by moving from that&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;DERIVED&gt;
xref:bsl/optional-072/2constructor-097.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;t&lowbar;DERIVED&gt;] original);
----

[.small]#xref:bsl/optional-072/2constructor-097.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()` moved&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
xref:bsl/optional-072/2constructor-00e.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&gt;] original);
----

[.small]#xref:bsl/optional-072/2constructor-00e.adoc[_» more&period;&period;&period;_]#

Explicitly create an `optional` by moving from the specified `original` using the specified `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
explicit
xref:bsl/optional-072/2constructor-07d.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef&lowbar;Deduced&lt;optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&gt;] original);
----

[.small]#xref:bsl/optional-072/2constructor-07d.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
xref:bsl/optional-072/2constructor-087.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:bsl/optional-072.adoc[optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;] const& original);
----

[.small]#xref:bsl/optional-072/2constructor-087.adoc[_» more&period;&period;&period;_]#

Explicitly create an `optional` from the specified `original` using the specified `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
explicit
xref:bsl/optional-072/2constructor-09e.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    xref:bsl/optional-072.adoc[optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;] const& original);
----

[.small]#xref:bsl/optional-072/2constructor-09e.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
xref:bsl/optional-072/2constructor-09c.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt; const& original);
----

[.small]#xref:bsl/optional-072/2constructor-09c.adoc[_» more&period;&period;&period;_]#

Explicitly create an `optional` from the specified `std&colon;&colon;optional` `original` using the specified `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
explicit
xref:bsl/optional-072/2constructor-0d1.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt; const& original);
----

[.small]#xref:bsl/optional-072/2constructor-0d1.adoc[_» more&period;&period;&period;_]#

Create an `optional` object whose contained value is initialized by forwarding from the specified `value`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
xref:bsl/optional-072/2constructor-0fb.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    t&lowbar;ANY&lowbar;TYPE&& value);
----

[.small]#xref:bsl/optional-072/2constructor-0fb.adoc[_» more&period;&period;&period;_]#

Create an `optional` object whose contained value is initialized by forwarding from the specified `value`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE = t&lowbar;TYPE&gt;
explicit
xref:bsl/optional-072/2constructor-03e.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    t&lowbar;ANY&lowbar;TYPE&& value);
----

[.small]#xref:bsl/optional-072/2constructor-03e.adoc[_» more&period;&period;&period;_]#

Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original&period;value()` moved&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
xref:bsl/optional-072/2constructor-04f.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&& original);
----

[.small]#xref:bsl/optional-072/2constructor-04f.adoc[_» more&period;&period;&period;_]#

Explicitly create an `optional` by moving from the specified `std&colon;&colon;optional` `original` using the specified `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;ANY&lowbar;TYPE&gt;
explicit
xref:bsl/optional-072/2constructor-01f.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::optional&lt;t&lowbar;ANY&lowbar;TYPE&gt;&& original);
----

[.small]#xref:bsl/optional-072/2constructor-01f.adoc[_» more&period;&period;&period;_]#

Create an `optional` object having the value of the (template parameter) `t&lowbar;TYPE` created in place using the specified `il` and specified `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;INIT&lowbar;LIST&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
constexpr
explicit
xref:bsl/optional-072/2constructor-0a8.adoc[optional](
    std::in&lowbar;place&lowbar;t inPlace,
    std::initializer&lowbar;list&lt;t&lowbar;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/optional-072/2constructor-0a8.adoc[_» more&period;&period;&period;_]#

Create an `optional` object having the value of the (template parameter) `t&lowbar;TYPE` created in place using the specified `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class&period;&period;&period; t&lowbar;ARGS&gt;
explicit
xref:bsl/optional-072/2constructor-064.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::in&lowbar;place&lowbar;t inPlace,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/optional-072/2constructor-064.adoc[_» more&period;&period;&period;_]#

Assign a new value to this optional&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;INIT&lowbar;LIST&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
explicit
xref:bsl/optional-072/2constructor-086.adoc[optional](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/optional-072.adoc[AllocType] allocator,
    std::in&lowbar;place&lowbar;t inPlace,
    std::initializer&lowbar;list&lt;t&lowbar;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/optional-072/2constructor-086.adoc[_» more&period;&period;&period;_]#

== Parameters

[cols="1,4"]
|===
| Name| Description
| *original*
| source optional used to initialize this object
| *nullopt*
| disengaged&hyphen;optional tag&semi; value is unused
| *value*
| value compared with or used to initialize the optional
| *allocatorArg*
| tag selecting the allocator&hyphen;extended constructor
| *allocator*
| allocator used to supply memory
| *inPlace*
| tag selecting in&hyphen;place construction of the contained
| *args*
| arguments forwarded to construct the contained value value
| *il*
| initializer list forwarded to construct the contained value
|===


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