Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2003-11-21 15:01:17


On 11/20/2003 06:13 PM, John Torjo wrote:
[snip]
> Could you explain a little further, please? I took a look at the code,
> but failed to see it. Anyway, interesting coding style;)
It "flattens" a heirarchy of containers using an optimized stack of
iterators. For example, the classical way of traversing a tree
without using recursion is to use a stack. The "stack" in this case
is actually the stack of classes in the inheritance heirarchy of
an iterator. The stack is optimized in that the stack is implemented
as the member m_iter's in each class in the class inheritance
heirarchy; hence, there's no virtual function calls which would be
needed in case an actual stack were used, whose members would have
to be pointers to members of some bridge iterator with virtual
functions.

Anyway, I realize the code is obscure; so, I've uploaded
*/shared_cyclic_ptr/iterator_flattened.cpp which just uses
a multidimensional array to illustrate the concept. HTH.
>
> What does empty() do - why doesn't it just compare two iterators?

I was wrong. The code in iterator_flattened just checks the
highest rank array. But the increment and deref operators
(in the iterator_array_stack<RankTop,RankNow+1,Element> ) use
not just 1 iterator_range, but 1 iterator_range for each rank.
So, not just 2 iterators will always work.


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