std::packaged_task
De cppreference.com
|
|
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. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <future>
|
||
template< class > class packaged_task; //not defined |
(1) | (depuis C++11) |
template< class R, class Args... > class packaged_task<R(Args...)>; |
(2) | (depuis C++11) |
Le modèle
std::packaged_task classe encapsule une cible appelable (fonction, expression lambda, l'expression de liaison, ou un autre objet de fonction) de sorte qu'il peut être appelée de façon asynchrone, et sa valeur de retour ou exception levée est stockée dans l'état partagé, qui peut être consultée par le biais std::future objets .Original:
The class template
std::packaged_task wraps any callable target (function, lambda expression, bind expression, or another function object) so that it can be invoked asynchronously, and its return value or exception thrown is stored in the shared state, which can be accessed through std::future 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.
Tout comme std::function,
std::packaged_task est un polymorphe, allocateur-aware conteneur: la cible appelable stockées peuvent être allouées sur le tas ou avec un allocateur fournie .Original:
Just like std::function,
std::packaged_task is a polymorphic, allocator-aware container: the stored callable target may be allocated on heap or with a provided allocator.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.
Fonctions membres
construit l'objet de la tâche Original: constructs the task object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
Détruit l'objet de la tâche Original: destructs the task object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
déplace l'objet tâche Original: moves the task object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
vérifie si l'objet de la tâche a une fonction valide Original: checks if the task object has a valid function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
swaps de deux objets de tâche Original: swaps two task objects The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
Original: Getting the result The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
renvoie une std::future associé au résultat promis Original: returns a std::future associated with the promised result The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
Original: Execution The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
exécute la fonction Original: executes the function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
exécute la fonction de faire en sorte que le résultat est prêt une fois que le thread courant Original: executes the function ensuring that the result is ready only once the current thread exits The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
réinitialise l'état des résultats enregistrés l'abandon des exécutions précédentes Original: resets the state abandoning any stored results of previous executions The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) | |
Fonctions annexes
(C++11) |
l'algorithme spécialisé std::swap Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) |
Classes d'aide
se spécialise le trait de type std::uses_allocator Original: specializes the std::uses_allocator type trait The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe générique spécialisée) | |
Exemple
#include <iostream>
#include <future>
#include <thread>
int main()
{
std::packaged_task<int()> task([](){return 7;}); // wrap the function
std::future<int> result = task.get_future(); // get a future
std::thread(std::move(task)).detach(); // launch on a thread
std::cout << "Waiting...";
result.wait();
std::cout << "Done!\nResult is " << result.get() << '\n';
}
Résultat :
Waiting...Done!
Result is 7
Voir aussi
(C++11) |
attend une valeur qui est définie de manière asynchrone Original: waits for a value that is set asynchronously The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe générique) |