class template


template <class T> function;     // undefined
template <class Ret, class... Args> class function<Ret(Args...)>;
Function wrapper
Class that can wrap any kind of callable element (such as functions and function objects) into a copyable object, and whose type depends solely on its call signature (and not on the callable element type itself).

An object of a function class instantiation can wrap any of the following kinds of callable objects: a function, a function pointer, a pointer to member, or any kind of function object (i.e., an object whose class defines operator(), including closures).

A decay copy of the wrapped callable object is stored internally by the object, which becomes the function's target. The specific type of this target callable object is not needed in order to instantiate the function wrapper class; only its call signature.

The function object can be copied and moved around, and can be used to directly invoke the callable object with the specified call signature (see member operator()).

function objects can also be in a state with no target callable object. In this case they are known as empty functions, and calling them throws a bad_function_call exception.

Template parameters

A type.
The generic template is not defined. Only the one that specializes T as the function type Ret(Args...).
The type resulting from invoking the functional call.
Types of the arguments.
This is a template parameter pack with any number of types.
For pointers to members, the first type shall be a reference to the class type the member pointed is a member.

Member types

member typedefinition
argument_typeIf Args... is a single type, it is an alias of this single type.
Otherwise, not defined.
first_argument_typeIf Args... is a pack of exactly two types, it is an alias of the first type.
Otherwise, not defined.
second_argument_typeIf Args... is a pack of exactly two types, it is an alias of the second type.
Otherwise, not defined.
Note that, except for result_type, the other member types are not always defined.

Member functions

Non-member function overloads