名前空間
変種
操作

「cpp/thread/packaged task/reset」の版間の差分

提供: cppreference.com
(Fix some translations)
 
1行: 1行:
{{tr_note}}
 
 
{{cpp/thread/packaged_task/title | reset}}
 
{{cpp/thread/packaged_task/title | reset}}
 
{{cpp/thread/packaged_task/navbar}}
 
{{cpp/thread/packaged_task/navbar}}
{{ddcl | notes={{mark since c++11}} |
+
{{ddcl | sincec++11 |
 
void reset();
 
void reset();
 
}}
 
}}
  
{{tr|リセットした状態では、以前の実行の結果を放棄する。新しい共有状態が構築されます.|Resets the state abandoning the results of previous executions. New shared state is constructed.}}
+
  
{{tr|{{c|1=*this = packaged_task(std::move(f))}}が格納されているタスクである{{tt|f}}、に相当します|Equivalent to {{c|1=*this = packaged_task(std::move(f))}}, where {{tt|f}} is the stored task.}}
+
{{c|1=*this = packaged_task(std::move(f))}} {{tt|f}}
  
===パラメータ===
+
======
 
(なし)
 
(なし)
  
===値を返します===
+
======
 
(なし)
 
(なし)
  
 
===例外===
 
===例外===
* {{tr|{{lc|std::future_error}}場合{{c|*this}}ない共有状態を持っていません。エラー条件が{{ltt|cpp/thread/future_errc|no_state}}に設定されています.|{{lc|std::future_error}} if {{c|*this}} has no shared state. The error condition is set to {{ltt|cpp/thread/future_errc|no_state}}.}}
+
* {{c|*this}} {{lc|std::future_error}}{{ltt|cpp/thread/future_errc|no_state}}
* {{tr|{{lc|std::bad_alloc}}新しい共有された状態のために十分なメモリがなかった場合..|{{lc|std::bad_alloc}} if there was not enough memory for a new shared state.}}
+
* {{lc|std::bad_alloc}}
* {{tr|いずれかの例外は新しい[[cpp/thread/packaged_task/packaged_task |コンストラクタに移動します]]の{{tt|packaged_task}}によってスロー|any exception thrown by the [[cpp/thread/packaged_task/packaged_task |コンストラクタに移動します]] of the new {{tt|packaged_task}}}}
+
* {{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時点における最新版

 
 
スレッドサポートライブラリ
スレッド
(C++11)
(C++20)
(C++20)
this_thread 名前空間
(C++11)
(C++11)
(C++11)
相互排他
(C++11)
汎用ロック管理
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
条件変数
(C++11)
セマフォ
ラッチとバリア
(C++20)
(C++20)
フューチャー
(C++11)
(C++11)
(C++11)
(C++11)
 
 
void reset();
(C++11以上)

以前の実行の結果を放棄して状態をリセットします。 新しい共有状態が構築されます。

*this = packaged_task(std::move(f)) と同等です。 ただし f は格納されているタスクです。

目次

[編集] 引数

(なし)

[編集] 戻り値

(なし)

[編集] 例外

[編集]

#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