Boost logo

Boost Users :

Subject: Re: [Boost-users] Strange error while using BOOST_FOREACH
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-03-12 00:25:48

> My collection does not have a const iterator defined for it. I suppose that bothers the
> machinery in FOREACH even though I'm not asking for one here?

Let's take a look at the docs. The Foreach docs say [1] that Foreach is built
on top of Boost.Range, and supports types that satisfy the Single Pass Range

The Boost.Range iterator docs on the Single Pass Range Concept [2] say that
such ranges have associated iterator and const iterator types, accessible
by boost::range_iterator<X>::type and boost::range_iterator<const X>::type,

There are two methods for adapting a type to fit the Single Pass Range
Concept requirement. The most commonly used method [3] is to give your range
type methods named 'begin()' and 'end()' and typedefs named 'iterator' and
'const_iterator'. There is also another method suitable for cases where you
cannot modify the range type [4].

So yes, if you want your range type to work with Boost.Foreach, you should
employ one of those methods to make it compliant to the Single Pass Range
Concept (including having a const iterator).



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