
That's just what I needed! It makes much more sense now that you have
explained that iterator_adaptor adapts a base class, rather than an
iterator, as originally documented. The concept is amazingly powerful, and
now that I've cleared the first hurdle, I'm much more inclined to explore
other uses.
I've adapted your example to implement begin() and end() methods, with a
little test, and have attached the code. I hope you can include such an
example with the library.
Thanks again for your help.
Keith MacDonald
"David Abrahams"
"Keith MacDonald"
writes: You have proposed a very elegant solution, but I would defy anyone who does not understand the library inside out to arrive at that solution. The documentation (iterator/doc/index.html#iterator-facade-and-adaptor) states:
We're working on the docs. That document is the standards proposal, but the Boost (user-level) docs aren't complete yet.
"It is common to define a new iterator which behaves like another iterator, but which modifies some aspect of its behavior. For that purpose, the library supplies the iterator_adaptor class template, which is specially designed to take advantage of as much of the underlying iterator's behavior as possible."
In this case, I can't see what the underlying iterator is, so don't understand how iteration can proceed.
I quote:
The iterator_adaptor class template adapts some Base 3 type to create a new iterator. Instantiations of iterator_adaptor are derived from a corresponding instantiation of iterator_facade and implement the core behaviors in terms of the Base type. In essence, iterator_adaptor merely forwards all operations to an instance of the Base type, which it stores as a member.
[3] The term "Base" here does not refer to a base class and is not meant to imply the use of derivation. We have followed the lead of the standard library, which provides a base() function to access the underlying iterator object of a reverse_iterator adaptor.
The user of iterator_adaptor creates a class derived from an instantiation of iterator_adaptor and then selectively redefines some of the core member functions described in the table above. The Base type need not meet the full requirements for an iterator. It ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ need only support the operations used by the core interface functions of iterator_adaptor that have not been redefined in the user's derived class.
For example, if you add the statement "++x;" to your example, it fails to compile.
Umm, sorry. I whipped that one off without too much testing. I've enclosed a fixed one.
---------------------------------------------------------------------------- ----
To return to my point about the purpose of a software library, my approach is generally to ask if it will allow me to implement code more quickly and reliably than without it. I got to the point of thinking, I've now got to implement a straightforward iterator, sigh, so will the boost library help me? I didn't expect to have to develop a deep understanding of template metaprogramming and the curiously recurring template pattern, before I could move on.
Why would you need to develop either of those? You just follow the formula.
Hence my plea for an example of a plain vanilla iterator, by which I meant something similar to those used for the std library containers.
I'm sorry, I need you to be more specific. Is the example of your node iterator good enough?
-- Dave Abrahams Boost Consulting www.boost-consulting.com
---------------------------------------------------------------------------- ----
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
begin 666 baz2.cpp
M+R\@8F%Z,BYC<' Z($)I9&ER96-T:6]N86P@:71E