Get each nth element of iterator range(获取迭代器范围的每个第 n 个元素)
问题描述
是否有任何标准实现(意味着 stdlib 或 boost)的迭代器包装另一个迭代器并只给出它的每个第 n 个元素?
Is there any standard implementation (meaning stdlib or boost) of an iterator that wraps another iterator and gives only each nth element of it?
我最初认为这可以通过合适的谓词和 boost::filter_iterator 来实现,但是谓词只获取值而不是基迭代器,因此它无法判断到开始的距离.
I first thought this would be possible with a fitting predicate and boost::filter_iterator, but the predicate gets only the value and not the base iterator, so it cannot tell the distance to the start.
编辑
提供更多信息:迭代器应该与 std::transform
或 std::copy
等函数兼容.所以它应该像 stdlib 迭代器一样使用.
Edit
To give some more information:
The iterator should be compatible with functions like std::transform
or std::copy
.
So it should be used like stdlib iterators.
类似问题:
C++/STL: std::transform with given stride?
具有非随机访问迭代器的非单元迭代器步幅
推荐答案
Boost.Range 提供 一个步幅适配器.使用 boost::begin
/boost::end
将为您提供相关的迭代器.
Boost.Range provides a stride adaptor. Using boost::begin
/boost::end
would net you the associated iterators.
这篇关于获取迭代器范围的每个第 n 个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取迭代器范围的每个第 n 个元素


- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01