std::function::operator()
De cppreference.com
< cpp | utility | functional | function
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
R operator()( ArgTypes... args)const; | (depuis C++11) | |
Appelle la fonction stockée cible appelable avec les paramètres
args
.Original:
Calls the stored callable function target with the parameters
args
.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.
Sommaire |
[modifier]Paramètres
args | - | paramètres à passer à la cible appelable fonction stockée Original: parameters to pass to the stored callable function target The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifier]Retourne la valeur
Aucun si
R
est void. Sinon, la valeur de retour de l'invocation de l'objet stocké appelable .Original:
None if
R
is void. Otherwise the return value of the invocation of the stored callable object.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.
[modifier]Exceptions
- std::bad_function_call si *this ne stocke pas une cible fonction accessible, !*this ==true .Original:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[modifier]Exemple
L'exemple suivant montre comment std::function peut passer à d'autres fonctions par valeur. En outre, il montre comment std::function peut stocker lambdas .
Original:
The following example shows how std::function can passed to other functions by value. Also, it shown how std::function can store lambdas.
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.
#include <iostream>#include <functional> void call(std::function<int()> f)// can be passed by value{std::cout<< f()<<'\n';} int normal_function(){return42;} int main(){int n =1;std::function<int()> f =[&n](){return n;}; call(f); n =2; call(f); f = normal_function; call(f);}
Résultat :
1 2 42
[modifier]Voir aussi
This section is incomplete |