「cpp/thread/packaged task/reset」の版間の差分
提供: cppreference.com
< cpp | thread | packaged task
細 (Fix some translations) |
|||
1行: | 1行: | ||
− | |||
{{cpp/thread/packaged_task/title | reset}} | {{cpp/thread/packaged_task/title | reset}} | ||
{{cpp/thread/packaged_task/navbar}} | {{cpp/thread/packaged_task/navbar}} | ||
− | {{ddcl | | + | {{ddcl | sincec++11 | |
void reset(); | void reset(); | ||
}} | }} | ||
− | + | ||
− | + | {{c|1=*this = packaged_task(std::move(f))}} {{tt|f}} | |
− | === | + | ====== |
(なし) | (なし) | ||
− | === | + | ====== |
(なし) | (なし) | ||
===例外=== | ===例外=== | ||
− | * | + | * {{c|*this}} {{lc|std::future_error}}{{ltt|cpp/thread/future_errc|no_state}} |
− | * | + | * {{lc|std::bad_alloc}} |
− | * | + | * {{tt|packaged_task}} [[cpp/thread/packaged_task/packaged_task |]] |
+ | |||
+ | |||
+ | {{| | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | packaged_task | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | }} | ||
[[de:cpp/thread/packaged task/reset]] | [[de:cpp/thread/packaged task/reset]] |
2018年4月8日 (日) 00:09時点における最新版
void reset(); |
(C++11以上) | |
以前の実行の結果を放棄して状態をリセットします。 新しい共有状態が構築されます。
*this = packaged_task(std::move(f)) と同等です。 ただし f
は格納されているタスクです。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
(なし)
[編集] 例外
- *this が共有状態を持っていない場合 std::future_error。 エラーコンディションは no_state に設定されます。
- 新しい共有状態のための十分なメモリがなかった場合 std::bad_alloc。
- 新しい
packaged_task
のムーブコンストラクタによって投げられるあらゆる例外。
[編集] 例
Run this code
#include <iostream> #include <cmath> #include <thread> #include <future> int main() { std::packaged_task<int(int,int)> task([](int a, int b) { return std::pow(a, b); }); std::future<int> result = task.get_future(); task(2, 9); std::cout << "2^9 = " << result.get() << '\n'; task.reset(); result = task.get_future(); std::thread task_td(std::move(task), 2, 10); task_td.join(); std::cout << "2^10 = " << result.get() << '\n'; }
出力:
2^9 = 512 2^10 = 1024