[#bsl-variant-2constructor-0e]
= xref:bsl.adoc[bsl]::xref:bsl/variant.adoc[variant]::variant
:relfileprefix: ../../
:mrdocs:

Constructors

== Synopses

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

Create a `variant` object holding a value&hyphen;initialized 0th alternative&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;FIRST&lowbar;ALT = t&lowbar;HEAD&gt;
requires std&colon;&colon;is&lowbar;default&lowbar;constructible&lt;t&lowbar;FIRST&lowbar;ALT&gt;&colon;&colon;value
xref:bsl/variant/2constructor-06.adoc[variant]();
----

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

Create a `variant` object holding a copy of `original`&apos;s alternative&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/variant/2constructor-034.adoc[variant](xref:bsl/variant.adoc[variant] const& original) = default;
----

[.small]#xref:bsl/variant/2constructor-034.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding a moved copy of `original`&apos;s alternative&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/variant/2constructor-07a.adoc[variant](xref:bsl/variant.adoc[variant]&& original) = default;
----

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

Create a `variant` object from a `std&colon;&colon;variant` `original`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;STD&lowbar;VARIANT&gt;
explicit
xref:bsl/variant/2constructor-011.adoc[variant](t&lowbar;STD&lowbar;VARIANT&& original);
----

[.small]#xref:bsl/variant/2constructor-011.adoc[_» more&period;&period;&period;_]#

Create a `variant` object whose contained value is initialized from `t`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;TYPE&gt;
xref:bsl/variant/2constructor-04.adoc[variant](t&lowbar;TYPE&& t);
----

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

Create a `variant` object holding a value&hyphen;initialized 0th alternative using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;FIRST = t&lowbar;HEAD&gt;
requires std&colon;&colon;is&lowbar;default&lowbar;constructible&lt;t&lowbar;FIRST&gt;&colon;&colon;value
xref:bsl/variant/2constructor-015.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator);
----

[.small]#xref:bsl/variant/2constructor-015.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding the `t&lowbar;INDEX` alternative from `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    std::size&lowbar;t t&lowbar;INDEX,
    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),
                                        t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-018.adoc[variant](
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt; inPlaceIndex,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/variant/2constructor-018.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding a `t&lowbar;TYPE` alternative from `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
requires BSLSTL&lowbar;VARIANT&lowbar;HAS&lowbar;UNIQUE&lowbar;TYPE(t&lowbar;TYPE) &amp;&amp;
                  std&colon;&colon;is&lowbar;constructible&lt;t&lowbar;TYPE, t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-0d1.adoc[variant](
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt; inPlaceType,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a copy of `original`&apos;s alternative using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;FIRST = t&lowbar;HEAD&gt;
requires BloombergLP&colon;&colon;bslstl&colon;&colon;
                Variant&lowbar;IsCopyConstructibleAll&lt;t&lowbar;FIRST, t&lowbar;TAIL&period;&period;&period;&gt;&colon;&colon;value
xref:bsl/variant/2constructor-0b.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    xref:bsl/variant.adoc[variant] const& original);
----

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

Create a `variant` object from a `std&colon;&colon;variant` `original` using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;STD&lowbar;VARIANT&gt;
explicit
xref:bsl/variant/2constructor-07b.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    t&lowbar;STD&lowbar;VARIANT&& original);
----

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

Create a `variant` object whose contained value is initialized from `t` using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;TYPE&gt;
xref:bsl/variant/2constructor-030.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    t&lowbar;TYPE&& t);
----

[.small]#xref:bsl/variant/2constructor-030.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding a moved copy of `original`&apos;s alternative using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class t&lowbar;FIRST = t&lowbar;HEAD&gt;
requires BloombergLP&colon;&colon;bslstl&colon;&colon;
                Variant&lowbar;IsMoveConstructibleAll&lt;t&lowbar;FIRST, t&lowbar;TAIL&period;&period;&period;&gt;&colon;&colon;value
xref:bsl/variant/2constructor-026.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    xref:bsl/variant.adoc[variant]&& original);
----

[.small]#xref:bsl/variant/2constructor-026.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding the `t&lowbar;INDEX` alternative from `il` and `args`&period;


[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
explicit
xref:bsl/variant/2constructor-09.adoc[variant](
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt; inPlaceIndex,
    std::initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a `t&lowbar;TYPE` alternative from `il` and `args`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;TYPE,
    class INIT&lowbar;LIST&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
requires BSLSTL&lowbar;VARIANT&lowbar;HAS&lowbar;UNIQUE&lowbar;TYPE(t&lowbar;TYPE) &amp;&amp;
                  std&colon;&colon;is&lowbar;constructible&lt;t&lowbar;TYPE,
                                        std&colon;&colon;initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt;&amp;,
                                        t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-033.adoc[variant](
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt; inPlaceType,
    std::initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

[.small]#xref:bsl/variant/2constructor-033.adoc[_» more&period;&period;&period;_]#

Create a `variant` object holding the `t&lowbar;INDEX` alternative from `args` using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    std::size&lowbar;t t&lowbar;INDEX,
    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),
                                        t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-07fa.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt; inPlaceIndex,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a `t&lowbar;TYPE` alternative from `args` using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
requires BSLSTL&lowbar;VARIANT&lowbar;HAS&lowbar;UNIQUE&lowbar;TYPE(t&lowbar;TYPE) &amp;&amp;
                  std&colon;&colon;is&lowbar;constructible&lt;t&lowbar;TYPE, t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-0d0.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt; inPlaceType,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding the `t&lowbar;INDEX` alternative from `il` and `args` using `allocator`&period;


[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
explicit
xref:bsl/variant/2constructor-07f8.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt; inPlaceIndex,
    std::initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a `t&lowbar;TYPE` alternative from `il` and `args` using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class t&lowbar;TYPE,
    class INIT&lowbar;LIST&lowbar;TYPE,
    class&period;&period;&period; t&lowbar;ARGS&gt;
requires BSLSTL&lowbar;VARIANT&lowbar;HAS&lowbar;UNIQUE&lowbar;TYPE(t&lowbar;TYPE) &amp;&amp;
                  std&colon;&colon;is&lowbar;constructible&lt;t&lowbar;TYPE,
                                        std&colon;&colon;initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt;&amp;,
                                        t&lowbar;ARGS&period;&period;&period;&gt;&colon;&colon;value
explicit
xref:bsl/variant/2constructor-02d.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t allocatorArg,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt; inPlaceType,
    std::initializer&lowbar;list&lt;INIT&lowbar;LIST&lowbar;TYPE&gt; il,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

== Parameters

[cols="1,4"]
|===
| Name| Description
| *original*
| variant to copy
| *t*
| value used to initialize the selected alternative
| *allocatorArg*
| tag selecting the allocator&hyphen;extended overload
| *allocator*
| allocator used to supply memory
| *inPlaceIndex*
| tag selecting the `t&lowbar;INDEX` alternative
| *args*
| arguments used to construct the selected alternative
| *inPlaceType*
| tag selecting the `t&lowbar;TYPE` alternative
| *il*
| initializer list used to construct the selected alternative
|===


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