[#bsl-variant-emplace-01]
= xref:bsl.adoc[bsl]::xref:bsl/variant.adoc[variant]::emplace
:relfileprefix: ../../
:mrdocs:

Create the alternative with index (template parameter) `t&lowbar;INDEX` in place, direct&hyphen;initialized from the specified `il` and args&apos;, destroying any previously contained value first&period; Return a reference to the newly created contained value&period; If the alternative is allocator&hyphen;aware, it uses the allocator specified upon the construction of this `variant` object to supply memory&semi; passing an allocator argument to this method results in two allocators being passed to the alternative constructor, resulting in a likely compilation error&period; If the alternative constructor exits via an exception, this object may be left in the valueless by exception state&period; This method participates in overload resolution only if `t&lowbar;INDEX` is a valid alternative index and the designated alternative is constructible from `il` and `args`&period; For simplicity of implementation, this method differs from the standard in the following way&colon; &ast; `constexpr` is not implemented

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    std::size&lowbar;t t&lowbar;INDEX,
    class INIT&lowbar;LIST&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
requires (t&lowbar;INDEX &lt; 1 &plus; sizeof&period;&period;&period;(t&lowbar;TAIL)) &amp;&amp;
                  std&colon;&colon;is&lowbar;constructible&lt;BSLSTL&lowbar;VARIANT&lowbar;TYPE&lowbar;AT&lowbar;INDEX(t&lowbar;INDEX),
                                        std&colon;&colon;initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt;&amp;,
                                        t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
variant&lowbar;alternative&lt;t&lowbar;INDEX, variant&lt;t&lowbar;HEAD, t&lowbar;TAIL&period;&period;&period;&gt;&gt;::type&
emplace(
    std::initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----


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