[#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 the 0th alternative, which is value&hyphen;initialized&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; This constructor participates in overload resolution only if the 0th alternative is default constructible&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; `constexpr` is not implemented &ast; `noexcept` specification is not implemented


[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 the same alternative (if any) as the specified `original` object&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; If the `original` object is not valueless by exception&apos;, the contained value is copy&hyphen;constructed from the contained value of `original`&period; This constructor is deleted unless all alternatives are copy constructible&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; conditional triviality is not implemented &ast; `constexpr` is not implemented &ast; `noexcept` specification is not implemented


[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 the same alternative (if any) held by the specified `original`&period; If this `variant` is allocator&hyphen;aware, the allocator of `original` is used to supply memory&period; If `original` is not valueless by exception, the contained value is move&hyphen;constructed from the contained value of `original`&period; This constructor participates in overload resolution only if all alternatives are move constructible&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; conditional triviality is not implemented &ast; `constexpr` is not implemented &ast; `noexcept` specification is not implemented


[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 holding the same alternative (if any) held by the specified `original`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; If `original` is not valueless by exception, the contained value is copy&sol;move&hyphen;constructed from the contained value of `original`&period; This constructor participates in overload resolution only if all alternatives are copy&sol;move&hyphen;constructible&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 direct&hyphen;initialized from the specified `t`&period; The alternative selected is the best match among all alternatives for which the expression `t&lowbar;ALT&lowbar;TYPE x&lsqb;&rsqb;&equals; &lcub;std&colon;&colon;forward&lt;t&lowbar;TYPE&gt;(t)&rcub;&semi;` is well formed, and this constructor participates in overload resolution only if there is a unique best matching alternative and that alternative is constructible from `t`&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; Note that the cv&hyphen;qualification of an alternative type does not affect how well the alternative type matches an argument type&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; `constexpr` is not implemented &ast; `noexcept` specification is not implemented


[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 the 0th alternative, which is value&hyphen;initialized&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; This constructor participates in overload resolution only if the 0th alternative is default constructible&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,
    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 alternative with index (template parameter) `t&lowbar;INDEX`, direct&hyphen;initialized from the specified `args`&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; This constructor participates in overload resolution only if `t&lowbar;INDEX` is a valid alternative index and the designated alternative is constructible from `args`&period; For simplicity of implementation, this method differs from the standard in the following ways&colon; &ast; `constexpr` is not implemented


[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;,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a contained value of type (template parameter) `t&lowbar;TYPE`, direct&hyphen;initialized from the specified `args`&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; This constructor participates in overload resolutionly if `t&lowbar;TYPE` designates a unique alternative and is constructible from `args`&period; For simplicity of implementation, this method differs from the standard in the following way&colon; &ast; `constexpr` is not implemented


[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;,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding the same alternative (if any) as the specified `original` object&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; If the `original` object is not valueless by exception&grave;, the contained value is copy&hyphen;constructed from the contained value of `original`&period; This constructor is deleted unless all alternatives are copy constructible&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,
    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 holding the same alternative (if any) held by the specified `original`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; If `original` is not valueless by exception, the contained value is copy&sol;move&hyphen;constructed from the contained value of `original`&period; This constructor participates in overload resolution only if all alternatives are copy&sol;move&hyphen;constructible&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,
    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 direct&hyphen;initialized from the specified `t`&period; The alternative selected is the best match among all alternatives for which the expression `t&lowbar;ALT&lowbar;TYPE x&lsqb;&rsqb;&equals; &lcub;std&colon;&colon;forward&lt;t&lowbar;TYPE&gt;(t)&rcub;&semi;` is well formed, and this constructor participates in overload resolution only if there is a unique best matching alternative and that alternative is constructible from `t`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; Note that the cv&hyphen;qualification of an alternative type does not affect how well the alternative type matches an argument type&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,
    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 the same alternative (if any) held by the specified `original`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; If `original` is not valueless by exception, the contained value is move&hyphen;constructed from the contained value of `original`&period; This constructor participates in overload resolution only if all alternatives are move constructible&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,
    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 alternative with index (template parameter) `t&lowbar;INDEX`, direct&hyphen;initialized from the specified `il` and `args`&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; This constructor 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


[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;,
    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 contained value of type (template parameter) `t&lowbar;TYPE`, direct&hyphen;initialized from the specified `il` and `args`&period; If this `variant` is allocator&hyphen;aware, the currently installed default allocator is used to supply memory&period; This constructor participates in overload resolution only if `t&lowbar;TYPE` designates a unique alternative and is constructible 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;,
    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 alternative with index (template parameter) `t&lowbar;INDEX`, direct&hyphen;initialized from the specified `args`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; This constructor participates in overload resolution only if `t&lowbar;INDEX` is a valid alternative index and the designated alternative is constructible 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-07fa.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt;,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding a contained value of type (template parameter) `t&lowbar;TYPE`, direct&hyphen;initialized from the specified `args`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator `is used to supply memory&period; This constructor participates in overload resolutionly if `t&lowbar;TYPE` designates a unique alternative and is constructible 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-0d0.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt;,
    t&lowbar;ARGS&&&period;&period;&period; args);
----

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

Create a `variant` object holding the alternative with index (template parameter) `t&lowbar;INDEX`, direct&hyphen;initialized from the specified `il` and `args`&period; If this `variant` is allocator&hyphen;aware, the specified `allocator` is used to supply memory&period; This constructor 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;


[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,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;index&lowbar;t&lt;t&lowbar;INDEX&gt;,
    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 contained value of type (template parameter) `t&lowbar;TYPE`, direct&hyphen;initialized from the specified `il` and `args`&period; If this `variant` is allocator&hyphen;aware, the specified &grave;allocator &grave;is used to supply memory&period; This constructor participates in overload resolutionly if `t&lowbar;TYPE` designates a unique alternative and is constructible 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-02d.adoc[variant](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/variant/allocator_type.adoc[allocator&lowbar;type] allocator,
    bsl::in&lowbar;place&lowbar;type&lowbar;t&lt;t&lowbar;TYPE&gt;,
    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;_]#


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