Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-22 08:47:14


Vladimir Prus <ghost_at_[hidden]> writes:

> Hello,
> I've just used the iterators_facade class to create a new iterator which takes
> a vector or vectors and traverses elements contained in inner vectors.
> This was pretty simple, and worked nice, but I have a few questions
>
> 1. The only docs I've seen tell that "AccessCategory" parameter should be of
> "unsigned" type. Yet in practice one has to pass
> boost::writable_lvalue_iterator_tag, which is class. Is something out-of-date
> there?

Yes. We revised the paper for the upcoming Kona meeting and the
implementation hasn't caught up yet. You can check out an earlier
version of the paper from the CVS if you need a reference.

> 2. I must admit this is the first time I create complete iterator with
> iterator_facade, so I'd really appreciate if someone takes a brief look and
> tells if there are any blunders. The code is at
>
> http://zigzag.cs.msu.su:7813/nested_vector_iterator.hpp

You need at least a default constructor for an lvalue iterator.
It looks to me as though the equal() function could be much much
simpler, but I may be missing something.

I don't notice any other problems.

> 3. If the code is OK, may I add it to Boost one day? My primary motivation was
> to make vector<vector<T> > model EdgeListGraph concept from BGL, so if I
> change vector_as_graph.hpp, this iterator must be added, too. If it's okay,
> where can it be added?
>
> 4. How const version of the iterator it to be created? Should I create a base
> class which defines dereference/advance/equal and derive const/non-const
> iterator from that?

I think it may be sufficient to pass const T as your iterator
parameter (and conditionally choose readable_lvalue_iterator_tag if V
is const).

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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