std::function (3) - Linux Manuals
std::function: std::function
NAME
Synopsis
Defined in header <functional>
template< class > (since C++11)
class function; /* undefined */
template< class R, class... Args > (since C++11)
class function<R(Args...)>;
Class template std::function is a general-purpose polymorphic function wrapper. Instances of std::function can store, copy, and invoke any Callable target -- functions, lambda_expressions, bind_expressions, or other function objects, as well as pointers to member functions and pointers to data members.
The stored callable object is called the target of std::function. If a std::function contains no target, it is called empty. Invoking the target of an empty std::function results in std::bad_function_call exception being thrown.
std::function satisfies the requirements of CopyConstructible and CopyAssignable.
Member types
Type Definition
result_type R
argument_type(deprecated in C++17)(removed in C++20) T if sizeof...(Args)==1 and T is the first and only type in Args...
first_argument_type(deprecated in C++17)(removed in C++20) T1 if sizeof...(Args)==2 and T1 is the first of the two types in Args...
second_argument_type(deprecated in C++17)(removed in C++20) T2 if sizeof...(Args)==2 and T2 is the second of the two types in Args...
Member functions
constructor (public member function)
destructor (public member function)
operator= (public member function)
swap (public member function)
assign assigns a new target
(until C++17)
operator_bool (public member function)
operator() (public member function)
Target access
target_type (public member function)
target (public member function)
Non-member functions
std::swap(std::function) specializes the std::swap algorithm
(C++11)
operator== (function template)
operator!=
Helper classes
std::uses_allocator<std::function> specializes the std::uses_allocator type trait
(C++11) (until C++17)
Deduction_guides(since C++17)
Example
// Run this code