Namespaces
Variants
Views
Actions

std::function::function

From cppreference.com
< cpp‎ | utility‎ | functional‎ | function
Revision as of 00:50, 7 January 2013 by Nikayama NDos (Talk | contribs)

 
 
 
Function objects
Function wrappers
(C++11)
(C++11)
Bind
(C++11)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
Deprecated binders and adaptors
(deprecated)
(deprecated)
(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)(deprecated)
(deprecated)(deprecated)
 
 

Template:ddcl list begin <tr class="t-dcl ">

<td >
function();
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
function( std::nullptr_t );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
function( const function& f );
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
function( function&& f );
</td>

<td > (4) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class F >
function( F f );
</td>

<td > (5) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc );
</td>

<td > (6) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Alloc >

function( std::allocator_arg_t, const Alloc& alloc,

          std::nullptr_t );
</td>

<td > (7) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Alloc >

function( std::allocator_arg_t, const Alloc& alloc,

          const function& f );
</td>

<td > (8) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Alloc >

function( std::allocator_arg_t, const Alloc& alloc,

          function&& f );
</td>

<td > (9) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class F, class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, F f );
</td>

<td > (10) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Constructs a std::function from a variety of sources.

1, 2, 6, 7) Create an empty function.
3, 8) Create a copy of f.
4, 9) Move the contents of f into *this.
5, 10) Move the Callable object f into *this.

Contents

Parameters

f - the function object used to initialize *this
alloc - an Allocator used for internal memory allocation

Notes

6-10) Constructors that have a first parameter of type std::allocator_arg_t must have a second argument alloc of type A that is an Allocator. This allocator is used to create memory for any internal data structures that the function might use.

5, 10) The type F should be CopyConstructible and the object f should be Callable. The resulting function object that is created will be empty if f is a NULL function pointer, a NULL pointer to member, or if f is a std::function and !f == true. The argument f is moved into the resulting function object.

Exceptions

1-2)
noexcept specification:  
noexcept
  

3-5) (none)

6-7)
noexcept specification:  
noexcept
  

8-10) (none)

Example