|
Boost Users : |
From: David Ward (david.ward_at_[hidden])
Date: 2007-01-02 21:06:16
I want to use a boost::filter_iterator to iterate through a std::vector
using a for-style loop. I haven't been able to find any examples of the
proper way to do this in the Boost documentation (or how to do this for any
other Boost iterator, for that matter).
>From searching this newsgroup, I found that it is possible to do:
for (boost::filter_iterator< ... > iter(myVector.begin(), myVector.end());
iter != boost::filter_iterator< ... >(myVector.end());
++iter )
{ ... }
However, iter is quite aware of when it has reached the end of the vector,
since that is the second parameter in its constructor. Is it really
necessary to create a second filter_iterator, set it to the end of the
vector, and then test iter against it? Can't I somehow test iter alone to
see if it has reached the end of the vector?
If I use std::for_each, it needs both a beginning and ending iterator as
parameters, leading to the same situation as above.
I've also looked at the Boost Range library and BOOST_FOREACH (described at
http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/foreach.html).
However, from my understanding, I don't think either of these apply to or
work with Boost iterators.
Whatever method is appropriate, I would ask that someone please exapnd the
Boost iterator documentation to include an example of using Boost iterators
in a for-style loop. I feel that this is a very basic and common usage of
iterators which was not addressed. Thank you.
-- David Ward Communications and Networking Division Information Technology and Telecommunications Laboratory Georgia Tech Research Institute
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net