◐ Shell
clean mode source ↗

std::packaged_task – cppreference.com

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>

definiert in Header

<future>

template< class > class packaged_task; //not defined

(1) (seit C++11)

template< class R, class Args... > class packaged_task<R(Args...)>;

(2) (seit C++11)

Das Klassen-Template std::packaged_task wickelt jede aufrufbare Ziel (Funktion, Lambda-Ausdruck, bind Ausdruck oder eine andere Funktion Objekt), so dass es asynchron aufgerufen werden kann, und dessen Rückgabewert oder Ausnahme ausgelöst wird im gemeinsamen Staat, die durch zugegriffen werden kann std::future Objekte .

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.

Genau wie std::function, std::packaged_task ist ein polymorpher, allocator-aware Container: die gespeicherte kündbare Ziel kann auf Heap oder mit einem vorgesehenen allocator zugeordnet werden .

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.

Member-Funktionen

baut das Task-Objekt

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.


(öffentliche Elementfunktion) [edit]

zerstört sich die Task-Objekt

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.


(öffentliche Elementfunktion) [edit]

bewegt das Task-Objekt

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.


(öffentliche Elementfunktion) [edit]

prüft, ob der Task-Objekt verfügt über eine gültige Funktion

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.


(öffentliche Elementfunktion) [edit]

Swaps zwei Task-Objekte

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.


(öffentliche Elementfunktion) [edit]

Erste das Ergebnis

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.

gibt eine std::future mit dem versprochenen Ergebnis assoziiert

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.


(öffentliche Elementfunktion) [edit]

Execution

Original:

Execution

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

führt die Funktion

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.


(öffentliche Elementfunktion) [edit]

führt die Funktion sicherzustellen, dass das Ergebnis fertig ist erst einmal die aktuelle Thread beendet

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.


(öffentliche Elementfunktion) [edit]

setzt der Staat aufzugeben, alle gespeicherten Ergebnisse der vorherigen Ausführungen

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.


(öffentliche Elementfunktion) [edit]

Non-Member-Funktionen

spezialisiert die std::swap Algorithmus

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.


(Funktions-Template) [edit]

Helper-Klassen

spezialisiert die std::uses_allocator Typ Merkmal

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.


(class Template-Spezialisierung) [edit]

Beispiel

#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

Siehe auch

wartet auf einen Wert, der asynchron ist

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.


(Klassen-Template) [edit]