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

Forward declaration&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class PROTOTYPE&gt;
class function
    : public xref:BloombergLP/bslstl/Function_Variadic-0e.adoc[BloombergLP::bslstl::Function&lowbar;Variadic&lt;PROTOTYPE&gt;]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bslstl/Function_Variadic-0e.adoc[BloombergLP::bslstl::Function&lowbar;Variadic&lt;PROTOTYPE&gt;]`
| This component&hyphen;private class template contains the physical representation and provides the variadic interfaces for `bsl&colon;&colon;function`&period;
|===

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/function-0a/allocator_type.adoc[`allocator&lowbar;type`] 
| Alias for the allocator type of the function representation&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/function-0a/2constructor-075.adoc[`function`]         [.small]#[constructor]#
| Constructors
| xref:bsl/function-0a/operator_assign-01.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/function-0a/allocator.adoc[`allocator`] 
| Return `get&lowbar;allocator()&period;mechanism()`&period; Note that this function exists for BDE compatibility and is not part of the C&plus;&plus; Standard Library&period;
| xref:bsl/function-0a/get_allocator.adoc[`get&lowbar;allocator`] 
| Return (a copy of) the allocator used to supply memory for this `function`&period;
| xref:bsl/function-0a/isInplace.adoc[`isInplace`] 
| Return `true` if this `function` is empty or if it is non&hyphen;empty and its target qualifies for the small&hyphen;object optimization (and is thus allocated within this object&apos;s footprint)&semi; otherwise, return false&period;
| xref:bsl/function-0a/swap.adoc[`swap`] 
| Exchange the targets held by this `function` and the specified `other` `function`&period; The behavior is undefined unless `get&lowbar;allocator() &equals;&equals; other&period;get&lowbar;allocator()`&period;
| xref:bsl/function-0a/target-0a9.adoc[`target`] 
| `target` overloads
| xref:bsl/function-0a/target_type.adoc[`target&lowbar;type`] 
| Return `typeid(void)` if this object is empty&semi; otherwise `typeid(FUNC)` where `FUNC` is the type of the target object&period;
| xref:bsl/function-0a/2conversion-05.adoc[`operator BloombergLP::bdef&lowbar;Function&lt;PROTOTYPE*&gt;&`] 
| Return `&ast;this`, converted to a mutable `bdef&lowbar;Function` reference by downcasting&period; The behavior is undefined unless `bdef&lowbar;Function&lt;F&ast;&gt;` is derived from `bsl&colon;&colon;function&lt;F&gt;` and adds no new data members&period;
| xref:bsl/function-0a/2conversion-0d.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;function, UsesAllocatorArgT&gt;`] 
| Nested trait declaration for `bslmf&colon;&colon;UsesAllocatorArgT`&period;
| xref:bsl/function-0a/2conversion-0a.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;function, UsesBslmaAllocator&gt;`] 
| Nested trait declaration for `bslma&colon;&colon;UsesBslmaAllocator`&period;
| xref:bsl/function-0a/2conversion-07.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;function, is&lowbar;nothrow&lowbar;move&lowbar;constructible&gt;`] 
| Nested trait declaration for `is&lowbar;nothrow&lowbar;move&lowbar;constructible`&period;
| xref:bsl/function-0a/2conversion-03.adoc[`operator bool`] 
| (C&plus;&plus;11 and later) Return false if this object is empty, otherwise return true&period; Note that this is an explicit conversion operator and is typically invoked implicitly in contexts such as in the condition of an `if` or `while` statement, though it can also be invoked via an explicit cast&period;
| xref:bsl/function-0a/2conversion-0c.adoc[`operator BloombergLP::bdef&lowbar;Function&lt;PROTOTYPE*&gt; const&`] 
| Return `&ast;this` converted to a const `bdef&lowbar;Function` reference by downcasting&period; The behavior is undefined unless `bdef&lowbar;Function&lt;F&ast;&gt;` is derived from `bsl&colon;&colon;function&lt;F&gt;` and adds no new data members&period;
|===


== Using Declarations

[cols="1,4"]
|===
| Name| Description
| xref:bsl/function-0a/operator().adoc[`operator()`] 
| If this object is empty, throw `bsl&colon;&colon;bad&lowbar;function&lowbar;call`&semi; otherwise invoke the target object with the specified `args&period;&period;&period;` and return the result (after conversion to `RET`)&period; Note that, even though it is declared `const`, this call operator can mutate the target object and is thus considered a manipulator rather than an accessor&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/function-00.adoc[`function&lt;PROTOTYPE&gt;`] 
| Deduce the template parameter `PROTOTYPE` from the signature of the `operator()` of the functor supplied to the constructor of `function`&period;
| xref:bsl/function-066.adoc[`function&lt;PROTOTYPE&gt;`] 
| Deduce the template parameter `PROTOTYPE` from the signature of the `operator()` of the functor supplied to the constructor of `function`&period;
| xref:bsl/function-06d.adoc[`function&lt;RET(ARGS&period;&period;&period;)&gt;`] 
| Deduce the template parameter `PROTOTYPE` from the signature of the function supplied to the constructor of `function`&period;
| xref:bsl/function-05.adoc[`function&lt;RET(ARGS&period;&period;&period;)&gt;`] 
| Deduce the template parameter `PROTOTYPE` from the signature of the function supplied to the constructor of `function`&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/operator_not_eq-0b.adoc[`operator!&equals;`]
| Return `true` if the specified `function` is not empty&period;
| xref:bsl/operator_eq-09d2.adoc[`operator&equals;&equals;`]
| Return true if the specified `function` argument is empty, otherwise return false&period;
| xref:bsl/swap-026.adoc[`swap`]
| Exchange the targets held by the specified `a` and specified `b` objects&period; The behavior is undefined unless &apos;a&period;get&lowbar;allocator() &equals;&equals; b&period;get&lowbar;allocator()&apos;&period;
|===


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