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 个元素


基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16