[#BloombergLP-bslstl-Optional_Base-05-emplace-0c]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::xref:BloombergLP/bslstl/Optional_Base-05.adoc[Optional&lowbar;Base]::emplace
:relfileprefix: ../../../
:mrdocs:

Destroy any contained value and construct a new one in place&period;

== Synopsis

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

[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;
t&lowbar;TYPE&
emplace(
    std::initializer&lowbar;list&lt;t&lowbar;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

== Description

Assign to this `Optional&lowbar;Base` object the value of the (template parameter) `t&lowbar;TYPE` created in place using the specified `il` and specified `args` and return a reference providing modifiable access to the underlying `t&lowbar;TYPE` object&period; If this `Optional&lowbar;Base` object already contains an object (`true &equals;&equals; hasValue()`), that object is destroyed before the new object is created&period; The allocator specified at the construction of this `Optional&lowbar;Base` object is used to supply memory to the value object&period; Attempts to explicitly specify via `args` another allocator to supply memory to the created (value) object are disallowed by the compiler&period; Note that if the constructor of `t&lowbar;TYPE` throws an exception this object is left in a disengaged state&period;

== Return Value

reference providing modifiable access to the contained value

== Parameters

[cols="1,4"]
|===
| Name| Description
| *il*
| initializer list forwarded to construct the contained value
| *args*
| arguments forwarded to construct the contained value
|===


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