[#bsl-function-0a-2constructor-075]
= xref:bsl.adoc[bsl]::xref:bsl/function-0a.adoc[function]::function
:relfileprefix: ../../
:mrdocs:

Constructors

== Synopses

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

Create an empty `function` that does not target any callable&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-0a.adoc[function]() noexcept;
----

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

Create a `function` having the same value as (i&period;e&period;, wrapping a copy of the target held by) the specified `original` object&period; Optionally specify an `allocator` (e&period;g&period;, the address of a `bslma&colon;&colon;Allocator` object) to supply memory&semi; otherwise, the default allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-070.adoc[function](xref:bsl/function-0a.adoc[function] const& original);
----

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

Create an empty `function` that does not target any callable&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-0b.adoc[function](xref:bsl/nullptr_t-08.adoc[nullptr&lowbar;t]) noexcept;
----

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

Create a `function` having the same target as the specified `original` object&period; Use `original&period;get&lowbar;allocator()` as the allocator to supply memory&period; The `original` object is set to empty after the new object is created&period; If the target qualifies for the small&hyphen;object optimization (see class&hyphen;level documentation), then it is move&hyphen;constructed into the new object&semi; otherwise ownership of the target is transferred without using the target&apos;s move constructor&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-074.adoc[function](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;function&gt;] original) noexcept;
----

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

Create an object wrapping the specified `func` callable object&period; Use the default allocator to supply memory&period; If `func` is a null pointer or null pointer&hyphen;to&hyphen;member, then the resulting object will be empty&period; This constructor will not participate in overload resolution if `func` is of the same type as (or reference compatible with) this object (to avoid ambiguity with the copy and move constructors) or is an integral type (to avoid matching null pointer literals)&period; In C&plus;&plus;03, this function will not participate in overload resolution if `FUNC` is a `MovableRef` (see overload, below), and instantiation will fail unless `FUNC` is invocable using the arguments and return type specified in `PROTOTYPE`&period; In C&plus;&plus;11 and later, this function will not participate in overload resolution if `FUNC` is not invocable using the arguments and return type specified in `PROTOTYPE`&period; Note that this constructor implicitly converts from any type that is so invocable&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class FUNC&gt;
xref:bsl/function-0a/2constructor-03f.adoc[function](FUNC&& func)
requires ! IsReferenceCompatible&lt;typename Decay&lt;FUNC&gt;&colon;&colon;type,
                                            function&gt;&colon;&colon;value
                 &amp;&amp;   IsInvocableWithPrototype&lt;
                                             typename Decay&lt;FUNC&gt;&colon;&colon;type&gt;&colon;&colon;value;
----

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

Create an empty `function` object using the specified `allocator` (e&period;g&period;, the address of a `bslma&colon;&colon;Allocator` object) to supply memory&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-03b1.adoc[function](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/function-0a/allocator_type.adoc[allocator&lowbar;type] const& allocator) noexcept;
----

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

Create an empty `function` object&period; Optionally specify an `allocator` (e&period;g&period;, the address of a `bslma&colon;&colon;Allocator` object) to supply memory&semi; otherwise, the default allocator is used&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-02.adoc[function](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/function-0a/allocator_type.adoc[allocator&lowbar;type] const& allocator,
    xref:bsl/nullptr_t-08.adoc[nullptr&lowbar;t]) noexcept;
----

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

Create a `function` having the same value as (i&period;e&period;, wrapping a copy of the target held by) the specified `original` object&period; Use the specified `allocator` (e&period;g&period;, the address of a `bslma&colon;&colon;Allocator` object) to supply memory&period; If `allocator &equals;&equals; original&period;allocator()`, this object is created as if by move construction&semi; otherwise it is created as if by extended copy construction using `allocator`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-03bb.adoc[function](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/function-0a/allocator_type.adoc[allocator&lowbar;type] const& allocator,
    xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef&lt;function&gt;] original);
----

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

Create a `function` having the same value as the specified `original` object, using the specified `allocator` to supply memory&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:bsl/function-0a/2constructor-0d.adoc[function](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/function-0a/allocator_type.adoc[allocator&lowbar;type] const& allocator,
    xref:bsl/function-0a.adoc[function] const& original);
----

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

Create an object wrapping the specified `func` callable object&period; Use the specified `allocator` (i&period;e&period;, the address of a `bslma&colon;&colon;Allocator` object) to supply memory&period; If `func` is a null pointer or null pointer&hyphen;to&hyphen;member, then the resulting object will be empty&period; This constructor will not participate in overload resolution if `func` is of the same type as (or reference compatible with) this object (to avoid ambiguity with the extended copy and move constructors) or is an integral type (to avoid matching null pointer literals)&period; In C&plus;&plus;03, this function will not participate in overload resolution if `FUNC` is a `MovableRef` (see overload, below), and instantiation will fail unless `FUNC` is invocable using the arguments and return type specified in `PROTOTYPE`&period; In C&plus;&plus;11 and later, this function will not participate in overload resolution if `FUNC` is not invocable using the arguments and return type specified in `PROTOTYPE`&period; Note that this constructor implicitly converts from any type that is so invocable&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class FUNC&gt;
xref:bsl/function-0a/2constructor-0e.adoc[function](
    std::allocator&lowbar;arg&lowbar;t,
    xref:bsl/function-0a/allocator_type.adoc[allocator&lowbar;type] const& allocator,
    FUNC&& func)
requires ! IsReferenceCompatible&lt;typename Decay&lt;FUNC&gt;&colon;&colon;type,
                                            function&gt;&colon;&colon;value
                 &amp;&amp;   IsInvocableWithPrototype&lt;
                                             typename Decay&lt;FUNC&gt;&colon;&colon;type&gt;&colon;&colon;value;
----

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


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