在C++標準庫中,有兩種“期望”,使用兩種類型模板實現,聲明在頭文件中:唯一期望(unique futures)(std::future<>)和共享期望(shared futures)(std::shared_future<>)
案列1:使用std::future從異步任務中獲取返回值
#include <future>
#include <iostrean>
int find_the_answer_to_ltuae();
void do_other_stuff();
int main()
{
std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
do_other_stuff();
std::cout << "The answer is" << the_answer.get() << std::endl;
}