![](/img/trans.png)
[英]Why a template argument of a rvalue reference type can be bound to a lvalue type?
[英]why std::future template argument type is reference type?
我正在http://en.cppreference.com/w/cpp/thread/future上查看std::future
文档
我不明白的是,为什么模板参数类型(在2
)是reference
?
template< class T > class future<T&>; (2) (since C++11)
这是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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.