std::function::operator()
Da cppreference.com.
< cpp | utility | functional | function
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
R operator()( ArgTypes... args ) const; |
(dal C++11) | |
Calls the stored callable function target with the parameters args
.
Indice |
[modifica] Parametri
args | - | parameters to pass to the stored callable function target |
[modifica] Valore di ritorno
None if R
is void. Otherwise the return value of the invocation of the stored callable object.
[modifica] Eccezioni
- std::bad_function_call if *this does not store a callable function target, !*this == true.
[modifica] Esempio
The following example shows how std::function can passed to other functions by value. Also, it shown how std::function can store lambdas.
#include <iostream> #include <functional> void call(std::function<int()> f) // can be passed by value { std::cout << f() << '\n'; } int normal_function() { return 42; } int main() { int n = 1; std::function<int()> f = [&n](){ return n; }; call(f); n = 2; call(f); f = normal_function; call(f); }
Output:
1 2 42
[modifica] Vedi anche
This section is incomplete |