Boost logo

Boost Users :

From: Keith MacDonald (boost_at_[hidden])
Date: 2004-01-06 13:44:16


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" <dave_at_[hidden]> wrote in message
news:uwu85i0my.fsf_at_boost-consulting.com...
> "Keith MacDonald" <boost_at_[hidden]> 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_at_[hidden]
> 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<F%T;W(@97AA;7!L92X-
M"B\O(%1O(&)U:6QD('=I=&@@35-60SH_at_8VP@+45(<V,@+4E<0U937&)O;W-T
M(&)A>C(N8W!P#0H-"B-I;F-L=61E(#QI;W-T<F5A;3X-"B-I;F-L=61E(#QB
M;V]S="]I=&5R871O<B]I=&5R871O<E]A9&%P=&]R+FAP<#X-"@T*+R\@:71E
M<B!C86X_at_8F4@=7-E9"!T;R!D96-L87)E('-T86YD87)D+"!B:61I<F5C=&EO
M;F%L(&ET97)A=&]R<PT*+R\@9F]R(&%N>2!C;&%S<R!6+"!W:&EC:"!H87,@
M<')E=B_at_I(&%N9"!N97AT*"D@;65M8F5R<RX-"@T*=&5M<&QA=&4@/&-L87-S
M(%8^#0IS=')U8W0@:71E<@T*"3H_at_8F]O<W0Z.FET97)A=&]R7V%D87!T;W(\
M:71E<CQ6/BP_at_5BHL(%8L(&)O;W-T.CIB:61I<F5C=&EO;F%L7W1R879E<G-A
M;%]T86<^#0I[#0H)='EP961E9_at_T*"0E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;W0N96YD*"D[#0H-"@DO+R!/=71P=70@<VAO=6QD(&)E.B Q
M(#(@,PT*(" @(&9O<B H3F]D93HZ:71E<F%T;W(@:70@/2!R;V]T+F)E9VEN
M*"D[(&ET("$](&ET16YD.R K*VET*0T*"0ES=&0Z.F-O=70@/#P@*"II="DN
H=F%L=64H*2 \/"!S=&0Z.F5N9&P[#0H-"@ER971U<FX@,#L-"GT-"@``
`
end

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net