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 个元素
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
