Описание тега std-function
A C++11 class template that is callable like a function, and wraps another callable type and forwards calls to it.
In the words of the C++11 standard std::function
is a polymorphic wrapper class that encapsulates arbitrary callable objects. It is polymorphic because an instance of the type std::function<R (A1, A2)>
could wrap an object of many different callable types, including:
- a function pointer of type
R (*)(A1, A2)
- a function pointer of type
R (*)(const A1&, const A2&)
- a function object (a.k.a functor) with a member function such as
R C::operator()(A1, A2)
- a pointer to member function of type
R (A1::*)(A2)
- a lambda
[](A1 a1, A2 a2) -> R {...}
std::function
is often used to implement generic callbacks or to support passing arbitrary callable types to a function that cannot be written as function template e.g. because it must be virtual
.
Use this tag for questions about std::function
and std::tr1::function
.