[#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. Use the currently installed default allocator to supply memory. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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()` converted to `t_TYPE` otherwise. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an lvalue of `const t_ANY_TYPE`, and is implicit only when an lvalue of `const t_ANY_TYPE` is implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when neither `t_TYPE` nor `t_ANY_TYPE` is allocator‐aware. [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. Use the currently installed default allocator to supply memory. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- constexpr xref:bsl/optional-072/2constructor-0d3.adoc[optional](xref:bsl/nullopt_t.adoc[bsl::nullopt_t]) 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 and converted to `t_TYPE` otherwise. Use the allocator from `original` to supply memory if `t_ANY_TYPE` is a non‐const version of `t_TYPE`; otherwise, use the currently installed default allocator. `original` is left in a valid but unspecified state. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an xvalue of `t_ANY_TYPE`, and is implicit only when an xvalue of `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when neither `t_TYPE` nor `t_ANY_TYPE` is allocator‐aware. [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()` converted to `t_TYPE` otherwise. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an lvalue of `const t_ANY_TYPE`, and is implicit only when an lvalue of `const t_ANY_TYPE` is implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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()` converted to `t_TYPE` otherwise. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an lvalue of `const t_ANY_TYPE`, and is explicit only when an lvalue of `const t_ANY_TYPE` is not implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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`. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from `t_ANY_TYPE` and is implicit only when `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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`. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from `t_ANY_TYPE` and is explicit only when `t_ANY_TYPE` is not implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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()` converted to `t_TYPE` otherwise. Use the currently installed default allocator to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an xvalue of `t_ANY_TYPE`, and is implicit only when an xvalue of `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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`. Use the currently installed default allocator to supply memory. [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. Use the specified `allocator` to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-0e.adoc[optional]( std::allocator_arg_t, 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`. Use the currently installed default allocator to supply memory. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-0c8.adoc[_» more..._]# Create a disengaged `optional` object. Use the specified `allocator` to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-08f.adoc[optional]( std::allocator_arg_t, xref:bsl/optional-072.adoc[AllocType] allocator, xref:bsl/nullopt_t.adoc[bsl::nullopt_t]); ---- [.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 disengaged `optional` object. Use the specified `allocator` to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/optional-072/2constructor-06c.adoc[optional]( std::allocator_arg_t, 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 value; otherwise, create a disengaged `optional` object. Use the specified `allocator` to supply memory. `original` is left in a valid, but unspecified state. Note that this constructor does not participate in overload resolution unless `optional` is an accessible base class of `t_DERIVED` or `t_DERIVED` is `optional` itself (in which case the instantiation provides the allocator‐extended move constructor). [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_DERIVED> xref:bsl/optional-072/2constructor-097.adoc[optional]( std::allocator_arg_t, 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 and converted to `t_TYPE` otherwise. Use the specified `allocator` to supply memory. `original` is left in a valid but unspecified state. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an xvalue of `t_ANY_TYPE`, and is implicit only when an xvalue of `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-00e.adoc[optional]( std::allocator_arg_t, 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, 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()` converted to `t_TYPE` otherwise. Use the specified `allocator` to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an lvalue of `const t_ANY_TYPE`, and is implicit only when an lvalue of `const t_ANY_TYPE` is implicitly convertible to `t_TYPE`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-087.adoc[optional]( std::allocator_arg_t, 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, 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()` converted to `t_TYPE` otherwise. Use the specified `allocator` to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an lvalue of `const t_ANY_TYPE`, and is implicit only when an lvalue of `const t_ANY_TYPE` is implicitly convertible to `t_TYPE`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-09c.adoc[optional]( std::allocator_arg_t, 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, 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`. Use the specified `allocator` to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from `t_ANY_TYPE`, and is implicit only when `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. [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, 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`. Use the specified `allocator` to supply memory. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from `t_ANY_TYPE`, and is explicit only when `t_ANY_TYPE` is not implicitly convertible to `t_TYPE`. [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, 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 and converted to `t_TYPE` otherwise. Use the specified `allocator` to supply memory. `original` is left in a valid but unspecified state. Note that this constructor participates in overload resolution only when `t_TYPE` is constructible from an xvalue of `t_ANY_TYPE`, and is implicit only when an xvalue of `t_ANY_TYPE` is implicitly convertible to `t_TYPE`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class t_ANY_TYPE> xref:bsl/optional-072/2constructor-04f.adoc[optional]( std::allocator_arg_t, 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, 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`. Use the currently installed default allocator to supply memory. This constructor can be called in constant expressions only when `t_TYPE` is not allocator‐aware. [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, 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`. Use the specified `allocator` to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class... t_ARGS> explicit xref:bsl/optional-072/2constructor-064.adoc[optional]( std::allocator_arg_t, xref:bsl/optional-072.adoc[AllocType] allocator, std::in_place_t, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-064.adoc[_» more..._]# Create an `optional` object having the value of the (template parameter) `t_TYPE` created in place using the specified `il` and `args`. Use the specified `allocator` to supply memory. [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, xref:bsl/optional-072.adoc[AllocType] allocator, std::in_place_t, std::initializer_list<t_INIT_LIST_TYPE> il, t_ARGS&&... args); ---- [.small]#xref:bsl/optional-072/2constructor-086.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#