Boost logo

Boost :

From: dan marsden (danmarsden_at_[hidden])
Date: 2006-05-06 18:11:58


Larry Evans wrote:
>In extension.htm, there's a section:
>
> Designing a suitable iterator
>
>which has code:
>
>template<typename Struct, int Pos>
>struct example_struct_iterator
> : iterator_base<example_struct_iterator<Struct, Pos> >
>{
> BOOST_STATIC_ASSERT(Pos >=0 && Pos < 3);
> typedef Struct struct_type;
> typedef mpl::int_<Pos> index;
> typedef example_struct_iterator_tag ftag;
> typedef random_access_traversal_tag category;
>
> example_struct_iterator(Struct& str)
> : struct_(str) {}
>
> Struct& struct_;
>};
>
>However, there's no declaration of example_struct_iterator_tag. I
>assume it can just be declared (no need to define it) like
>the example_sequence_tag occuring just below the section titled:

There's going to be a couple of changes in this example. You are correct
though that a forward declaration of example_struct_iterator_tag is
needed, if only to make the docs clearer.

>
> Enabling Tag Dispatching
>
>Actually, I think that's another typo, IOW instead of
>example_sequence_tag, it should be example_tag. But that
>makes me wonder if you didn't meand that
>example_struct_iterator_tag should also be example_tag.

The correct structure should be that the tag_of the example_struct
should be example_sequence_tag, and the tag_of the iterator
should be example_struct_iterator_tag. (There should be 2 distinct
tags). This should be tidied up and consistent in the next version of
the docs.

>Also, since the above code is all for a specific structure, i.e.
>example_struct, why is there any need for including a Struct
>template parameter. Why not just:
>
> template<int Pos>
> struct example_struct_iterator
> : iterator_base<example_struct_iterator<example_struct, Pos> >
> {
> BOOST_STATIC_ASSERT(Pos >=0 && Pos < 3);
> typedef example_struct struct_type;
> ...
> };

The Struct parameter allows us to capture whether the iterator points into
an example_struct or a const example_struct. Some of the rest of the example
code needs to make this distinction.

Thanks for the feedback
Cheers
Dan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk