[boost-users][boost foreach, iterating]

hi, is their anyway where i can use boost foreach to iterate through two different containers at once. Like I have two vector of float and i want to iterate through them parallell.. (not using indexing.. since it doesn't work with all types). Thanks. Something that is equalivent to python, for x,y in xArray, yArray: # do some awesome stuff. print x, y

chun ping wang wrote:
hi, is their anyway where i can use boost foreach to iterate through two different containers at once.
Like I have two vector of float and i want to iterate through them parallell.. (not using indexing.. since it doesn't work with all types). Thanks.
Something that is equalivent to python, for x,y in xArray, yArray: # do some awesome stuff. print x, y
Not directly, but you can get what you want with the help of some range
adapters. I haven't tried it, but it looks like the "zipped" adapter
from the Oven library can help here. See
http://p-stade.sourceforge.net/oven/doc/html/oven/utilities.html#oven.utilit....
Untested:
typedef boost::tuple

chun ping wang wrote:
hi, is their anyway where i can use boost foreach to iterate through two different containers at once.
Like I have two vector of float and i want to iterate through them parallell.. (not using indexing.. since it doesn't work with all types). Thanks.
Something that is equalivent to python, for x,y in xArray, yArray: # do some awesome stuff. print x, y
Don't you have to do: for x,y in zip (xArray, yArray): ?

yeah your right. Well yeah i want somethinlg like a zipped function for c++
that is maybe part of boost.
On Dec 2, 2007 12:11 PM, Neal Becker
chun ping wang wrote:
hi, is their anyway where i can use boost foreach to iterate through two different containers at once.
Like I have two vector of float and i want to iterate through them parallell.. (not using indexing.. since it doesn't work with all types). Thanks.
Something that is equalivent to python, for x,y in xArray, yArray: # do some awesome stuff. print x, y
Don't you have to do: for x,y in zip (xArray, yArray): ?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

chun ping wang wrote: hi, is their anyway where i can use boost foreach to iterate through two different containers at once. Like I have two vector of float and i want to iterate through them parallell.. (not using indexing.. since it doesn't work with all types). Thanks. Something that is equalivent to python, for x,y in xArray, yArray: # do some awesome stuff. print x, y This sounds like the zip iterator by David Abrahams and Thomas Becker. Take a look at http://www.boost.org/libs/iterator/doc/zip_iterator.html http://www.boost.org/libs/iterator/doc/zip_iterator.html and see if that does what you need.
participants (4)
-
Andrew Holden
-
chun ping wang
-
Eric Niebler
-
Neal Becker