迭代器或 std::iota 与常规 C++ 数组?

Joh*_*ith 0 c++ iteration foreach iota c++11

有没有办法达到与此相同的效果,

std::list<int> l(10);
std::iota(l.begin(), l.end(), -4);
Run Code Online (Sandbox Code Playgroud)

与常规int a[]

或者,以下是唯一的解决方法:

for (iterator itr = begin; itr != end; ++itr)
    /* ... visit *itr here ... */
Run Code Online (Sandbox Code Playgroud)

for*_*818 6

C++11 添加了std::beginstd::end. 从那时起就没有区别了:

std::list<int> l(10);
std::iota(std::begin(l),std::end(l), -4);
int a[10];
std::iota(std::begin(a),std::end(a), -4);
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

1359 次

最近记录:

3 年,1 月 前