
I used BOOST_FOREACH with a collection whose iterator is derived from
boost::iterator_adaptor. I got this:
7>E:\boost_1_47\boost/range/iterator.hpp(63): error C2039: 'type' : is not a member of
'boost::mpl::eval_if_c

Have you tried instantiating the range_const_iterator and range_mutable_iterator
metafunctions with the relevant types and checking that they actually have
::type members?
That is, do
typedef range_const_iterator

On 3/11/2012 6:10 AM, Nathan Ridge wrote:
Have you tried instantiating the range_const_iterator and range_mutable_iterator metafunctions with the relevant types and checking that they actually have ::type members?
That is, do
typedef range_const_iterator
::type T1; and
typedef range_mutable_iterator
::type T2; compile?
Regards, Nate
By 'your_range' I suppose that means the collection type I was trying to use in the FOREACH. I get an error for T1. 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? —John

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 Concept. 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, respectively. 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). Regards, Nate [1] http://www.boost.org/doc/libs/1_49_0/doc/html/foreach.html [2] http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/concepts/sing... [3] http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/ext... [4] http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/ext...
participants (2)
-
John M. Dlugosz
-
Nathan Ridge