std::function
Aus cppreference.com
| Defined in header <functional>
|
||
template< class > class function; /* undefined */ |
(seit C++11) | |
template< class R, class... Args > class function<R(Args...)> |
(seit C++11) | |
Vorlage Klasse
std::function ist ein Allzweck-polymorphe Funktion Wrapper. Instanzen std::function speichern können, zu kopieren, und rufen alle kündbaren Ziel - Funktionen, Lambda-Ausdrücke, bind Ausdrücke oder andere Funktion Objekte . Original:
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-Ausdrücke, bind Ausdrücke, or other function objects. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Mitglied Typen
Type
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
result_type
|
R
|
argument_type
|
T wenn sizeof...(Args)==1 und T ist das erste und einzige in Args... Original: T if sizeof...(Args)==1 and T is the first and only type in Args... The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first_argument_type
|
T1 wenn sizeof...(Args)==2 und T1 ist die erste der beiden Typen im Args... Original: T1 if sizeof...(Args)==2 and T1 is the first of the two types in Args... The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
second_argument_type
|
T2 wenn sizeof...(Args)==2 und T2 ist die zweite der beiden Typen im Args... Original: T2 if sizeof...(Args)==2 and T2 is the second of the two types in Args... The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Member-Funktionen
Vorlage:cpp/utility/functional/function/dcl list constructorVorlage:cpp/utility/functional/function/dcl list destructorVorlage:cpp/utility/functional/function/dcl list operator=Vorlage:cpp/utility/functional/function/dcl list swapVorlage:cpp/utility/functional/function/dcl list assignVorlage:cpp/utility/functional/function/dcl list operator boolVorlage:cpp/utility/functional/function/dcl list operator()Vorlage:cpp/utility/functional/function/dcl list target typeVorlage:cpp/utility/functional/function/dcl list target
Original: Target access The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Non-Member-Funktionen
Vorlage:cpp/utility/functional/function/dcl list swap2 vergleicht eine std::function mit std::nullptrOriginal: compares an std::function with std::nullptrThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
Helper-Klassen
Vorlage:cpp/utility/functional/function/dcl list uses allocatorBeispiel
#include <functional>
#include <iostream>
struct Foo {
Foo(int num) : num_(num) {}
void print_add(int i) const { std::cout << num_+i << '\n'; }
int num_;
};
void print_num(int i)
{
std::cout << i << '\n';
}
int main()
{
// store a free function
std::function<void(int)> f_display = print_num;
f_display(-9);
// store a lambda
std::function<void()> f_display_42 = []() { print_num(42); };
f_display_42();
// store the result of a call to std::bind
std::function<void()> f_display_31337 = std::bind(print_num, 31337);
f_display_31337();
// store a call to a member function
std::function<void(const Foo&, int)> f_add_display = &Foo::print_add;
Foo foo(314159);
f_add_display(foo, 1);
}
Output:
-9
42
31337
314160