2017-06-14 104 views

回答

1

這是爲std::future基準專業化佔的那些情況下,其中,返回值是一個引用類型。

檢查實例的以下示例代碼:

// future example 
#include <iostream>  // std::cout 
#include <future>   // std::async, std::future 


int counter = 0; 

int& increment_counter() 
{ 
    return ++counter; 
} 

int main() 
{ 
    std::future<int&> fut = std::async(increment_counter); 

    int &counterRef = fut.get(); 

    std::cout << "value:" << counterRef << std::endl; 

    return 0; 
}