std::packaged_task::reset

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

版本历史

  • (当前 | 先前 2017年9月25日 (一) 03:42Fruderica讨论 | 贡献. . (1,259字节) (-392). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:33P12bot讨论 | 贡献 . . (1,651字节) (+4). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 19:24P12bot讨论 | 贡献 . . (1,647字节) (+305). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:08P12讨论 | 贡献 . . (1,342字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,342字节) (+1,342). . (Translated from the English version using Google Translate)