Boost Users :
From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2002-06-04 00:02:49
--- At Tue, 4 Jun 2002 00:05:46 -0400, David Abrahams wrote:
>"Duane Murphy" <duanemurphy_at_[hidden]> wrote in message
>> --- At Mon, 3 Jun 2002 14:09:07 -0400, David Abrahams wrote:
>> >> Take a look at the documentation and implementation where it talks
>> >> default_iterator_policies. This shows you the functions that have to be
>> >> implemented by your base iterator class.
>> >This statement is a bit misleading. It shows the functions that your
>> >Policies class must implement.
>> Ah, what I was meaning was to look at the implementations of the
>> functions in default_iterator_policies. The implementation shows what
>> this policy calls and what default_iterator_policies expectes the base
>> iterator to be able to do. I have found it easier to write a simple
>> "iterator like" class and use the default_iterator_policies than to write
>> both an iterator and a policy.
>That's a pretty wacky idea! You're putting the behaviors in the Base object,
>but the library "intends" for behaviors to be specified by the Policies.
>In other words, the "normal" approach is to treat the Base object as raw
>data, and while the policies implement the operations on that data.
I really love iterators. I have worked at trying to figure out the
"right" way of doing a plain iterator. That is I have a "thing" that
looks like a container and has APIs for "iterating" the container but
those APIs dont really look like a standard iterator.
The canonical example is a file iterator; iterate over the files in a
directory. The directory appears to be a container with filenames as the
members of the container.
What would the base and policy objects be?
The way I have been doing it would be to first use the
default_iterator_policies. That's because I basically want a default
iterator. I dont have any iterator to assign policies to yet.
Next I define the simplest iterator required by the
default_iterator_policies. This is usually a forward iterator if copying
is practical given the nature of the API. Basically in the example, the
iterator would hold a DIR structure and use the standard DIR APIs to
"increment" and dereference the structure as required.
So, what is the "normal" way of creating an iterator out of thin air as
-- "If tyranny and oppression come to this land, it will be in the guise of fighting a foreign enemy." - James Madison
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