Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-10-22 10:37:15

David Abrahams wrote:

> 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.

Okay, thanks.

>> 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
> You need at least a default constructor for an lvalue iterator.

But that default ctor will leave all member iterators uninitialized. Is that

> It looks to me as though the equal() function could be much much
> simpler, but I may be missing something.

I haven't found a way to simplify it. If there were "nil" value, shared by
all iterators of the same type, I could have compared only "inner" values.
But since there's no "nil", it must check "outer" to tell if "inner" is
valid. For example, if initial vector is empty, I cannot set any value for
inner, without risk of crash.
> 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).
Gonna try it now... yes, it works. I only need to strip "const" when
declaring vector types, so that const iterator don't require
vector< vector<const int> > instead of vector< vector<int> >.
Thanks for the idea!

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at