使用std :: function成员从仅移动类型构造元组

问题描述

请考虑以下代码:

struct no_copy {
int x_;
std::function<void()> f_;

template <typename F>
no_copy(int x,F&& f)
    : x_{ x },f_{ std::forward<F>(f) } {};

no_copy(const no_copy&) = delete;
no_copy& operator= (const no_copy&)  = delete;

no_copy(no_copy&&) noexcept = default;
no_copy& operator= (no_copy&&) noexcept = default;
};

int main() {
auto nc = no_copy(1,[]() {});
auto tuple_func = std::make_tuple(std::move(nc),2);

return 0;
}

我正在尝试使用具有std::funtion<void()>成员的仅移动类型构造一个元组。在Visual Studio 2017下,此代码无法编译:

 error C2440: '<function-style-cast>': cannot convert from 'initializer list' to '_Ttype'
 note: No constructor could take the source type,or constructor overload resolution was ambiguous

如果我使复制构造函数= default一切正常。我知道这与std::function有关,但是我不确定是什么问题。

谢谢。

解决方法

这显然是一个实现错误:代码中根本没有初始化程序列表,并且所有编译器的当前版本为accept it(自v19.22以来的MSVC)。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...