获取迭代器范围中的每个第n个元素 [英] Get each nth element of iterator range
问题描述
有没有执行标准(即STDLIB或提升)的包装另一个迭代器,并只给它的每个第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?
我首先想到的,这将有可能与一个合适的predicate和boost :: filter_iterator,但predicate仅获取价值,而不是基本的迭代器,所以它不能告诉的距离开始。
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 ::变换
或的std ::复制
。
所以应该用于像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:性病::给定的步幅变换结果
<一href=\"http://stackoverflow.com/questions/9387569/non-unit-iterator-stride-with-non-random-access-iterators\">Non-unit迭代步幅与非随机访问迭代器
Similar questions:
C++/STL: std::transform with given stride?
Non-unit iterator stride with non-random access iterators
推荐答案
Boost.Range提供<一个href=\"http://www.boost.org/doc/libs/1_51_0/libs/range/doc/html/range/reference/adaptors/reference/strided.html\">a步幅适配器。使用的boost ::开始
/ 的boost ::结束
将净你相关的迭代器。
Boost.Range provides a stride adaptor. Using boost::begin
/boost::end
would net you the associated iterators.
这篇关于获取迭代器范围中的每个第n个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!