std::packaged_task
提供: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. |
| Defined in header <future>
|
||
| template< class > class packaged_task; //not defined |
(1) | (C + + 11以来) |
| template< class R, class Args... > class packaged_task<R(Args...)>; |
(2) | (C + + 11以来) |
クラステンプレート
std::packaged_taskは、それが非同期的に呼び出すこともできますので、任意の呼び出し可能なターゲット(関数、ラムダ式、バインド式、または別の関数オブジェクト)をラップし、スローその戻り値または例外がstd::futureを介してアクセス可能な共有状態に格納されオブジェクト.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.
ちょうどstd::functionような、ポリモーフィック
std::packaged_task、アロケータアウェアコンテナです:ストアド呼び出し可能なターゲットがヒープ上に、または提供のアロケータを割り当てるかもしれません.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.
[編集] メンバ関数
| タスクオブジェクトを構築します 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. (パブリックメンバ関数) | |
| タスクオブジェクトを破棄します 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. (パブリックメンバ関数) | |
| タスクオブジェクトを移動します 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. (パブリックメンバ関数) | |
| タスクオブジェクトかどうかをチェックするには、有効な機能を持っています 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. (パブリックメンバ関数) | |
| スワップ2タスクオブジェクト 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. (パブリックメンバ関数) | |
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. | |
| は約束された結果に関連付けられstd::futureを返す最初の引数が2番目の値より小さい'の場合 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. (パブリックメンバ関数) | |
Original: Execution The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| 関数が実行されます 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. (パブリックメンバ関数) | |
| 結果は一度だけ現在のスレッドが終了する準備ができていることを確保する関数を実行します 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. (パブリックメンバ関数) | |
| リセットされ、以前の実行のいずれかの格納された結果を放棄した状態 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. (パブリックメンバ関数) | |
[編集] 非メンバ関数
| 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. (関数テンプレート) | |
[編集] ヘルパークラス
| 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. (クラステンプレートの特殊化の2つの値を比較します) | |
[編集] 例
#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
[編集] も参照してください
| (C++11) |
非同期で設定された値を待ちます 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. (クラステンプレート) |