Std::fill_n的右值,是否只支持复制填充
std::fill_n of rvalues, does it only support filling by copy?
给定std::futures
的std::vector
std::vector<std::future<void>> futures;
为什么std::fill_n
抱怨我在传递右值时调用复制构造函数:
std::fill_n(std::back_inserter(futures), 10, std::async([]{ std::cout << "yon"; }));
error: use of deleted function future(const future&)
我的意思是,fill_n
不接收一个xvalue?如果没有,为什么不呢?
std::fill_n
复制作为第三个参数传递的给定对象,但第三个参数是不可复制的未来对象,因为复制未来没有意义。因此出现了错误。
你似乎需要这个:
std::generate_n(std::back_inserter(futures),
10,
[]{ return std::async([]{ std::cout << "yon"; }); });
std::fill_n
的接口为:
template< class OutputIt, class Size, class T >
OutputIt fill_n( OutputIt first, Size count, const T& value );
然后复制value
count
次。这就是你得到错误的原因。虽然,即使它移动,fill_n
作为功能的选择也没有意义……你会从同一个future
移动10次,所以你最终会得到一个有效的future
和9个空的?那有什么意义呢?
相关文章:
- MSVC是否支持C++11样式的属性而不是__declspec
- 如何检测VS C++编译器是否支持C++11?
- LMDB 是否支持随机读取?
- OpenCL 是否支持向量作为内核参数?
- "configure"脚本如何检测我的系统是否支持某些头文件或 cpp 功能?
- 基于 SFINAE 的特征,用于确定是否支持运算符 +
- CLion 是否支持自定义输入?如果是,我在哪里输入它们?
- 标准库中的任何正则表达式语法是否支持 (?(定义)用于子模式参考?
- GCP 或 AWS 是否支持 C++ 和 GUI 应用程序开发?
- Go 是否支持调用C++函数?
- libtorrent是否支持带摘要身份验证的http web种子
- 张量流 c++ API 是否支持反向传播的自动微分?
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- g++ 是否支持scalar_storage_order?
- 罗斯林是否支持C++生成语法树
- C++11: Atomic::compare_exchange_weak 是否支持非基元类型?
- gcc 是否支持 -static-libgcc 和 -fexceptions?
- Boost 1.64 是否支持 HP-UX?
- Armadillo是否支持布尔和8位型矩阵和立方体
- MSVC 2017 是否支持具有自动矢量化的 AVX 512