我想用STL算法生成一个矢量来实现以下
const int N1 = 10; // This can vary
const int offset = 3; // This also can vary
std::vector<int> chans(10);
for (size_t i = 0; i < chans.size(); i++)
{
chans[i] = offset + N1*i;
}
有什么建议吗?
答案 0 :(得分:6)
使用C ++ 14:
std::generate(chans.begin(), chans.end(),
[=, count = 0]() mutable { return offset + N1 * count++; });