std::packaged_task
Da cppreference.com.
![]() |
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. |
Elemento definito nell'header <future>
|
||
template< class > class packaged_task; //not defined |
(1) | (dal C++11) |
template< class R, class Args... > class packaged_task<R(Args...)>; |
(2) | (dal C++11) |
Il modello di classe
std::packaged_task
avvolge qualsiasi bersaglio callable (funzione, espressione lambda, espressione bind, o un altro oggetto funzione) in modo che possa essere richiamato in modo asincrono, e il suo valore di ritorno o eccezione generata è memorizzato in stato condiviso, a cui si accede attraverso std::future oggetti.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.
Proprio come std::function,
std::packaged_task
è un polimorfo, allocatore-aware contenitore: il bersaglio memorizzato callable può essere assegnato sul mucchio o con un allocatore disponibile.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.
[modifica] Membri funzioni
costruisce l'oggetto dell'attività 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. (metodo pubblico) | |
distrugge l'oggetto dell'attività 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. (metodo pubblico) | |
sposta l'oggetto dell'attività 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. (metodo pubblico) | |
Verifica se l'oggetto attività ha una funzione valida 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. (metodo pubblico) | |
Scambia due oggetti dell'attività 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. (metodo pubblico) | |
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. | |
restituisce un std::future associato al risultato promesso 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. (metodo pubblico) | |
Original: Execution The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
esegue la funzione 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. (metodo pubblico) | |
esegue la funzione di garantire che il risultato è solo una volta pronto il thread corrente 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. (metodo pubblico) | |
ripristina lo stato di abbandono tutti i risultati memorizzati di esecuzioni precedenti 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. (metodo pubblico) |
[modifica] Non membri funzioni
specializzata l'algoritmo 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. (funzione di modello) |
[modifica] Helper classi
specializzata il tratto tipo 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 modello di specializzazione) |
[modifica] Esempio
#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'; }
Output:
Waiting...Done! Result is 7
[modifica] Vedi anche
(C++11) |
attende per un valore che è impostato in modo asincrono 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 template) |