[#bsl-pair-0b-2constructor-089]
= xref:bsl.adoc[bsl]::xref:bsl/pair-0b.adoc[pair]::pair
:relfileprefix: ../../
:mrdocs:

Constructors

== Synopses

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

Construct a `pair` with the `first` and `second` members initialized to default values&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/pair-0b/2constructor-08c.adoc[pair]() = default;
----

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

Construct a `pair` from the specified `other` pair, holding `first` and `second` values of (template parameter) type `PARAM&lowbar;1` and `PARAM&lowbar;2` respectively&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2,
    class = void&gt;
requires std&colon;&colon;is&lowbar;constructible&lt;T1, const PARAM&lowbar;1&amp;&gt;&colon;&colon;value &amp;&amp;
                            std&colon;&colon;is&lowbar;constructible&lt;T2, const PARAM&lowbar;2&amp;&gt;&colon;&colon;value
constexpr
xref:bsl/pair-0b/2constructor-041.adoc[pair](xref:bsl/pair-0b.adoc[pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;] const& other);
----

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

Construct a `pair` from the specified `other` rvalue pair, holding `first` and `second` values of (template parameter) type `PARAM&lowbar;1` and `PARAM&lowbar;2` respectively&period; This method requires that `T1` and `T2` be convertible from `PARAM&lowbar;1` and `PARAM&lowbar;2`, respectively&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2,
    class = void&gt;
requires bsl&colon;&colon;is&lowbar;convertible&lt;PARAM&lowbar;1, T1&gt;&colon;&colon;value
                                    &amp;&amp; bsl&colon;&colon;is&lowbar;convertible&lt;PARAM&lowbar;2, T2&gt;&colon;&colon;value
constexpr
xref:bsl/pair-0b/2constructor-01.adoc[pair](xref:bsl/pair-0b.adoc[pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;]&& other);
----

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

Construct a default `pair`, using the specified `basicAllocator` to supply memory for each member when its type uses `bslma`&hyphen;style allocators&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
explicit
xref:bsl/pair-0b/2constructor-0d6.adoc[pair](xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Create a `pair` that has the same value as the specified `rhs` pair proxy&period; The behavior is undefined unless `T1` is constructible from `PARAM&lowbar;1` and `T2` is constructible from from `PARAM&lowbar;2`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
constexpr
xref:bsl/pair-0b/2constructor-0f.adoc[pair](xref:BloombergLP/bslma/ManagedPtr_PairProxy.adoc[BloombergLP::bslma::ManagedPtr&lowbar;PairProxy&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;] const& rhs);
----

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

Same as the preceding overload&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2,
    class = void&gt;
requires std&colon;&colon;is&lowbar;constructible&lt;T1, const PARAM&lowbar;1&amp;&gt;&colon;&colon;value &amp;&amp;
                            std&colon;&colon;is&lowbar;constructible&lt;T2, const PARAM&lowbar;2&amp;&gt;&colon;&colon;value
constexpr
xref:bsl/pair-0b/2constructor-0a.adoc[pair](std::pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt; const& other);
----

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

Same as the constructor taking `pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;&amp;&amp;`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2,
    class = void&gt;
requires bsl&colon;&colon;is&lowbar;convertible&lt;PARAM&lowbar;1, T1&gt;&colon;&colon;value
                                    &amp;&amp; bsl&colon;&colon;is&lowbar;convertible&lt;PARAM&lowbar;2, T2&gt;&colon;&colon;value
constexpr
xref:bsl/pair-0b/2constructor-03.adoc[pair](std::pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;&& other);
----

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

Construct a `pair` with the `first` member initialized to the specified `a` value and the `second` member initialized to the specified `b` value&period; Optionally specify a `basicAllocator`, used to supply memory for each of `first` and `second` when its type (template parameter `T1` or `T2`, respectively) uses `bslma`&hyphen;style allocators&period; This method requires that `T1` and `T2` be `copy&hyphen;constructible`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
constexpr
xref:bsl/pair-0b/2constructor-099e.adoc[pair](
    bsl::add&lowbar;lvalue&lowbar;reference&lt;T1 const&gt;::type a,
    bsl::add&lowbar;lvalue&lowbar;reference&lt;T2 const&gt;::type b);
----

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

Construct a `pair` having the same value as that of the specified `original` pair&period; Optionally specify a `basicAllocator`, used to supply memory for each of `first` and `second` when its type (template parameter `T1` or `T2`, respectively) uses `bslma`&hyphen;style allocators&period; Note that the copy constructor is implicitly declared (if `T1` and `T2` are both `copy&hyphen;constructible`) by compilers that do not support defaulted declarations&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/pair-0b/2constructor-0c.adoc[pair](
    xref:bsl/pair-0b.adoc[pair] const& original,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a pair having the same value as that of the specified `original` using the specified `basicAllocator` to supply memory for each of `first` and `second` when its type (template parameter `T1` or `T2`, respectively) uses `bslma`&hyphen;style allocators&period; Note that `original` is left in a valid but unspecified state&period; Also note that this method requires that `T1` and `T2` be move&hyphen;constructible&period; Note this this constructor will _not_ be deleted when the implicitly declared move constructor is deleted, and will produce an error when it is called in such cases&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/pair-0b/2constructor-099c.adoc[pair](
    xref:bsl/pair-0b.adoc[pair]&& original,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a `pair` from the specified `other` pair, using the specified `basicAllocator` to supply memory for each member when its type uses `bslma`&hyphen;style allocators&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-02f.adoc[pair](
    xref:bsl/pair-0b.adoc[pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;] const& other,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a `pair` from the specified `other` pair, using the specified `basicAllocator` to supply memory for each member when its type uses `bslma`&hyphen;style allocators&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-020.adoc[pair](
    std::pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt; const& other,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a `pair` from the specified rvalue `other` pair&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-0e.adoc[pair](
    xref:bsl/pair-0b.adoc[pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;]&& other,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a `pair` from the specified `other` rvalue pair, using the specified `basicAllocator` to supply memory for each member when its type uses `bslma`&hyphen;style allocators&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-06.adoc[pair](
    std::pair&lt;PARAM&lowbar;1, PARAM&lowbar;2&gt;&& other,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Construct a `pair` with the `first` member initialized to the specified `a` value and the `second` member initialized to the specified `b` value&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2,
    class = void&gt;
requires std&colon;&colon;is&lowbar;constructible&lt;T1, PARAM&lowbar;1&gt;&colon;&colon;value &amp;&amp;
                std&colon;&colon;is&lowbar;constructible&lt;T2, PARAM&lowbar;2&gt;&colon;&colon;value &amp;&amp;
                !(bsl&colon;&colon;is&lowbar;pointer&lt;bsl&colon;&colon;remove&lowbar;reference&lowbar;t&lt;PARAM&lowbar;2&gt;&gt;&colon;&colon;value &amp;&amp;
                  bsl&colon;&colon;is&lowbar;convertible&lt;PARAM&lowbar;2,
                                      BloombergLP&colon;&colon;bslma&colon;&colon;Allocator &ast;&gt;&colon;&colon;value)
constexpr
xref:bsl/pair-0b/2constructor-0db.adoc[pair](
    PARAM&lowbar;1&& a,
    PARAM&lowbar;2&& b);
----

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

Create a `pair` from the specified `a` and `b` lvalue references&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/pair-0b/2constructor-009.adoc[pair](
    bsl::add&lowbar;lvalue&lowbar;reference&lt;T1 const&gt;::type a,
    bsl::add&lowbar;lvalue&lowbar;reference&lt;T2 const&gt;::type b,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Create a `pair` from piece&hyphen;wise construction of `first` and `second` values by forwarding in order the elements in the specified `first&lowbar;args` and `second&lowbar;args` tuples to the corresponding constructor of (template parameter) types `T1` and `T2`, respectively&period; Optionally specify a `basicAllocator`, used to supply memory for each of `first` and `second` when its type (template parameter `T1` or `T2`, respectively) uses `bslma`&hyphen;style allocators&period; Allocators can also be passed as tuple members straight to `T1` or `T2` (or both) constructors using the first version (but use of the second version for this approach will result in a compile&hyphen;time error)&period; This method requires that `T1` and `T2` be constructible from (the variable number of template parameters) `ARGS&lowbar;1` and `ARGS&lowbar;2` respectively&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class&period;&period;&period; ARGS&lowbar;1,
    class&period;&period;&period; ARGS&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-096.adoc[pair](
    std::piecewise&lowbar;construct&lowbar;t,
    std::tuple&lt;ARGS&lowbar;1&period;&period;&period;&gt; first&lowbar;args,
    std::tuple&lt;ARGS&lowbar;2&period;&period;&period;&gt; second&lowbar;args);
----

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

Construct a `pair` with the `first` member initialized to the specified `a` value and the `second` member initialized to the specified `b` value, using the specified `basicAllocator` to supply memory for each member when its type uses `bslma`&hyphen;style allocators&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class PARAM&lowbar;1,
    class PARAM&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-00c.adoc[pair](
    PARAM&lowbar;1&& a,
    PARAM&lowbar;2&& b,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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

Same as the preceding constructor, using the specified `basicAllocator` to supply memory&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class&period;&period;&period; ARGS&lowbar;1,
    class&period;&period;&period; ARGS&lowbar;2&gt;
xref:bsl/pair-0b/2constructor-04f.adoc[pair](
    std::piecewise&lowbar;construct&lowbar;t,
    std::tuple&lt;ARGS&lowbar;1&period;&period;&period;&gt; first&lowbar;args,
    std::tuple&lt;ARGS&lowbar;2&period;&period;&period;&gt; second&lowbar;args,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator);
----

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


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