
shunsuke wrote:
So there are 3 library I am searching, 1) Index -> iterator , and iterator -> index conversion (I know that 2 famous facts in STL that iterator doesn't know container and their position, but that is only applicable for pointers . There is no harm to know this facts from iterator. and thus some library can do to-from conversion between iterator & index position , or better sub_range & pair<index_t,index_t> any library ?
Boost has 'counting_iterator'. http://www.boost.org/libs/iterator/doc/counting_iterator.html You can call 'counting_iterator::base()' if you want the 'index'.
2) a library like index_range, which hops over a container (random access preferably ) adding an user specified offset to the iterator position
Boost has 'permutation_iterator'. http://www.boost.org/libs/iterator/doc/permutation_iterator.html Unfortunately, 'boost::permutation_iterator' cannot work with 'boost::counting_iterator', hence requires a patch something like this.. http://tinyurl.com/35qkzw This one fits my need, thus I will replace my code by
3) an utility which allows to refer a portion (or some portions ) of a container to be stored ( i.e store by index & return by iterator ) inside another class , using the above two library ....
If you take the portions represented by different types into a single deque, Dr.Becker's 'any_iterator' is a candidate. http://thbecker.net/free_software_utilities/type_erasure_for_cpp_iterators/s... At present I don't need a polymorphic or heterogeneous iterator. I am looking at it. And also looking at some iterator adapter (or range ) which can be stored inside a class or another container. i.e it will perform all of
Here I am not getting the "index" from counting_iterator. std::vector<int> v; v+= 1,2,3,4,5,6,7,8,9,10; std::for_each(v.begin(),v.end(),std::cout<<_1<<" "); counting_iterator<std::vector<int>::iterator > it_b = make_counting_iterator(v.begin()+3); std::cout<<*it_b.base(); /// This prints the element at that pos i.e 4, not the position, i.e 3 . How to get the index back from iterator ? permutation_iterator. the operations using index & a reference to the container internally. Thus it needs to know the container & the position in the container. can any_iterator or some other be stored (or boost::sub_range of those iterator adapter) inside a class , or I need to store index and construct iterator with the help of container.
Well, you have to make a range by using these iterators, because Boost doesn't have the range wrappers yet. It would be something like this.. http://tinyurl.com/38474e
This is ok. I will be happy to use it.
Finally, I've written everything noted above. :-) http://tinyurl.com/2o2mnv
Still looking at them. Will get an idea within a day.
Regards,
Thanks for specifying the links, and sorry for disturbing. abir -- Abir Basak, Member IEEE B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com