std::packaged_task::reset(3)
π std::packaged_task::reset π
okay so bestie, this page is from the C++ Standard Libary manual β yes, thatβs literally the spelling on the page π β and itβs all about std::packaged_task::reset.
β¨ NAME β¨
std::packaged_task::reset β std::packaged_task::reset
itβs giving βsame name, same energy, one tiny functionβ π
πΈ Synopsis πΈ
void reset(); (since C++11)
so this baby has been around since C++11, periodt β¨
Resets the state abandoning the results of previous executions. New shared state is constructed.
Equivalent to *this = packaged_task(std::move(f)), where f is the stored task.
π Parameters π
(none) β literally no parameters, bestie π«Ά
π¦ Return value π¦
(none) β nope, nothing comes back π
π Exceptions π
std::future_errorif*thishas no shared state. The error condition is set tono_state.std::bad_allocif there was not enough memory for a new shared state.- Any exception thrown by the move constructor of the new
packaged_task.
like, if any of these pop off, itβs a whole thing π no cap.
π Example π
// Run this code
#include <cmath>
#include <future>
#include <iostream>
#include <thread>
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';
}
β Output β
2^9 = 512
2^10 = 1024
byeee π«Ά β source: http://cppreference.com, version/date: 2024.06.10, page: std::packaged_task::reset(3) π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms