[英]std::promise<T> where T must be default constructible in Visual Studio 2017?
I am trying to compile the following code in Visual Studio 2017:我正在尝试在 Visual Studio 2017 中编译以下代码:
#include <future>
int main()
{
std::promise<std::reference_wrapper<int>> promise;
(void)promise;
}
However, I get the following error:但是,我收到以下错误:
error C2512: 'std::reference_wrapper': no appropriate default constructor available
错误 C2512:“std::reference_wrapper”:没有合适的默认构造函数可用
Whereas it compiles fine with GCC and Clang.而它与 GCC 和 Clang 编译得很好。
Is this is a definite bug in Visual Studio or is it a valid implementation of std::promise?这是 Visual Studio 中的一个明确错误还是 std::promise 的有效实现?
Looks like it is a known issue in MSVC's standard library implementation.看起来这是 MSVC 标准库实现中的一个已知问题。 A simpler reproduction scenario:
一个更简单的再现场景:
#include <future>
struct NoDefaultCtor
{
NoDefaultCtor() = delete;
};
int main() {
std::promise<NoDefaultCtor> p;
return 0;
}
I suppose you do not need std::reference_wrapper<int>
.我想你不需要
std::reference_wrapper<int>
。 There is the suitable overloaded template for std::promise
available:有适用于
std::promise
重载模板可用:
template<class R> class promise<R&>;
Therefore you can fix your code in Visual Studio 2017:因此,您可以在 Visual Studio 2017 中修复您的代码:
#include <future>
int main()
{
std::promise<int&> promise;
(void)promise;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.