[#bsl-optional-072-2constructor-043] = xref:bsl.adoc[bsl]::xref:bsl/optional-072.adoc[optional]::optional :relfileprefix: ../../ :mrdocs: Constructors == Synopses Declared in `<bslstl_optional.h>` Create a disengaged `optional` object. [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..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr xref:bsl/optional-072/2constructor-07f.adoc[optional](xref:bsl/optional-072.adoc[optional<t_ANY_TYPE>] const& original); ---- [.small]#xref:bsl/optional-072/2constructor-07f.adoc[_» more..._]# Construct an `optional` in‐place from the specified arguments. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr explicit xref:bsl/optional-072/2constructor-0cb.adoc[optional](xref:bsl/optional-072.adoc[optional<t_ANY_TYPE>] const& original); ---- [.small]#xref:bsl/optional-072/2constructor-0cb.adoc[_» more..._]# Create a disengaged `optional` object. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- constexpr xref:bsl/optional-072/2constructor-0d3.adoc[optional](xref:bsl/nullopt_t.adoc[bsl::nullopt_t] nullopt) noexcept; ---- [.small]#xref:bsl/optional-072/2constructor-0d3.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()` moved. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr xref:bsl/optional-072/2constructor-080.adoc[optional](xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef_Deduced<optional<t_ANY_TYPE>>] original); ---- [.small]#xref:bsl/optional-072/2constructor-080.adoc[_» more..._]# Same as the preceding overload. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr explicit xref:bsl/optional-072/2constructor-004.adoc[optional](xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef_Deduced<optional<t_ANY_TYPE>>] original); ---- [.small]#xref:bsl/optional-072/2constructor-004.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr xref:bsl/optional-072/2constructor-035.adoc[optional](std::optional<t_ANY_TYPE> const& original); ---- [.small]#xref:bsl/optional-072/2constructor-035.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr explicit xref:bsl/optional-072/2constructor-013.adoc[optional](std::optional<t_ANY_TYPE> const& original); ---- [.small]#xref:bsl/optional-072/2constructor-013.adoc[_» more..._]# Create an `optional` object whose contained value is initialized by forwarding from the specified `value`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE = t_TYPE> constexpr xref:bsl/optional-072/2constructor-0af.adoc[optional](t_ANY_TYPE&& value); ---- [.small]#xref:bsl/optional-072/2constructor-0af.adoc[_» more..._]# Create an `optional` object whose contained value is initialized by forwarding from the specified `value`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE = t_TYPE> constexpr explicit xref:bsl/optional-072/2constructor-0c2.adoc[optional](t_ANY_TYPE&& value); ---- [.small]#xref:bsl/optional-072/2constructor-0c2.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr xref:bsl/optional-072/2constructor-05.adoc[optional](std::optional<t_ANY_TYPE>&& original); ---- [.small]#xref:bsl/optional-072/2constructor-05.adoc[_» more..._]# Explicitly create an `optional` by moving from the specified `std::optional` `original`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> constexpr explicit xref:bsl/optional-072/2constructor-0f0.adoc[optional](std::optional<t_ANY_TYPE>&& original); ---- [.small]#xref:bsl/optional-072/2constructor-0f0.adoc[_» more..._]# Create a disengaged `optional` object. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-0e.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator); ---- [.small]#xref:bsl/optional-072/2constructor-0e.adoc[_» more..._]# Create an `optional` object having the value of the (template parameter) `t_TYPE` created in place using the specified `args`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class... t_ARGS> constexpr explicit xref:bsl/optional-072/2constructor-0c8.adoc[optional]( std::in_place_t inPlace, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-0c8.adoc[_» more..._]# Create a disengaged `optional` object. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-08f.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:bsl/nullopt_t.adoc[bsl::nullopt_t] nullopt); ---- [.small]#xref:bsl/optional-072/2constructor-08f.adoc[_» more..._]# If the specified `original` contains a value, create an `optional` object whose contained value is initialized from `*original`; otherwise, create a. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-06c.adoc[optional]( std::allocator_arg_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..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_DERIVED> xref:bsl/optional-072/2constructor-097.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef_Deduced<t_DERIVED>] original); ---- [.small]#xref:bsl/optional-072/2constructor-097.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()` moved. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-00e.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef_Deduced<optional<t_ANY_TYPE>>] original); ---- [.small]#xref:bsl/optional-072/2constructor-00e.adoc[_» more..._]# Explicitly create an `optional` by moving from the specified `original` using the specified `allocator`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> explicit xref:bsl/optional-072/2constructor-07d.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:BloombergLP/bslmf/MovableRef_Deduced.adoc[BloombergLP::bslmf::MovableRef_Deduced<optional<t_ANY_TYPE>>] original); ---- [.small]#xref:bsl/optional-072/2constructor-07d.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-087.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:bsl/optional-072.adoc[optional<t_ANY_TYPE>] const& original); ---- [.small]#xref:bsl/optional-072/2constructor-087.adoc[_» more..._]# Explicitly create an `optional` from the specified `original` using the specified `allocator`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> explicit xref:bsl/optional-072/2constructor-09e.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, xref:bsl/optional-072.adoc[optional<t_ANY_TYPE>] const& original); ---- [.small]#xref:bsl/optional-072/2constructor-09e.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-09c.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::optional<t_ANY_TYPE> const& original); ---- [.small]#xref:bsl/optional-072/2constructor-09c.adoc[_» more..._]# Explicitly create an `optional` from the specified `std::optional` `original` using the specified `allocator`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> explicit xref:bsl/optional-072/2constructor-0d1.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::optional<t_ANY_TYPE> const& original); ---- [.small]#xref:bsl/optional-072/2constructor-0d1.adoc[_» more..._]# Create an `optional` object whose contained value is initialized by forwarding from the specified `value`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE = t_TYPE> xref:bsl/optional-072/2constructor-0fb.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, t_ANY_TYPE&& value); ---- [.small]#xref:bsl/optional-072/2constructor-0fb.adoc[_» more..._]# Create an `optional` object whose contained value is initialized by forwarding from the specified `value`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE = t_TYPE> explicit xref:bsl/optional-072/2constructor-03e.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, t_ANY_TYPE&& value); ---- [.small]#xref:bsl/optional-072/2constructor-03e.adoc[_» more..._]# Create a disengaged `optional` object if the specified `original` object is disengaged, and an `optional` object with the value of `original.value()` moved. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-04f.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::optional<t_ANY_TYPE>&& original); ---- [.small]#xref:bsl/optional-072/2constructor-04f.adoc[_» more..._]# Explicitly create an `optional` by moving from the specified `std::optional` `original` using the specified `allocator`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> explicit xref:bsl/optional-072/2constructor-01f.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::optional<t_ANY_TYPE>&& original); ---- [.small]#xref:bsl/optional-072/2constructor-01f.adoc[_» more..._]# Create an `optional` object having the value of the (template parameter) `t_TYPE` created in place using the specified `il` and specified `args`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class t_INIT_LIST_TYPE, class... t_ARGS> constexpr explicit xref:bsl/optional-072/2constructor-0a8.adoc[optional]( std::in_place_t inPlace, std::initializer_list<t_INIT_LIST_TYPE> il, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-0a8.adoc[_» more..._]# Create an `optional` object having the value of the (template parameter) `t_TYPE` created in place using the specified `args`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class... t_ARGS> explicit xref:bsl/optional-072/2constructor-064.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::in_place_t inPlace, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-064.adoc[_» more..._]# Assign a new value to this optional. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< class t_INIT_LIST_TYPE, class... t_ARGS> explicit xref:bsl/optional-072/2constructor-086.adoc[optional]( std::allocator_arg_t allocatorArg, xref:bsl/optional-072.adoc[AllocType] allocator, std::in_place_t inPlace, std::initializer_list<t_INIT_LIST_TYPE> il, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-086.adoc[_» more..._]# == Parameters [cols="1,4"] |=== | Name| Description | *original* | source optional used to initialize this object | *nullopt* | disengaged‐optional tag; value is unused | *value* | value compared with or used to initialize the optional | *allocatorArg* | tag selecting the allocator‐extended constructor | *allocator* | allocator used to supply memory | *inPlace* | tag selecting in‐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]#