Boost logo

Boost Users :

Subject: Re: [Boost-users] BOOST_FOREACH with Index
From: pete_at_[hidden]
Date: 2009-12-14 06:34:14

> Nat Goodspeed wrote:
> > Maybe this shouldn't be a BOOST_FOREACH feature at all. As with
> Python's
> > builtin enumerate() function, maybe what we want here is an
> iterator
> > adapter that dereferences to a std::pair
> original_iterator_value_type>?

> Couldn't you just do a BOOST_FOREACH over combine(count_range(),
> foos)
> for that?
> (uses zip_iterator)

Yup, Nat's idea is a nice one and easy to implement. As Eric alluded to with his reference to the ticket on FOREACH_FIELD, the heart of the matter really though is getting a syntactically convenient version. We've seen this situation - where we have the neat iterators/ranges but not the syntactic convenience - a few times (REVERSE_FOREACH, FOREACH_FIELD, this "FOREACH_WITHINDEX" spring to mind) - I wonder if there is an opportunity to expose a lower level API in the FOREACH mini-library that would enable advanced users to build such macros themselves.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at