Boost logo

Boost Users :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-06-04 08:45:12


"Duane Murphy" <duanemurphy_at_[hidden]> wrote in message
news:20020604050249.610_at_mail.murphyslogic.com...
> --- At Tue, 4 Jun 2002 00:05:46 -0400, David Abrahams wrote:

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

You have a misapprehension about the meaning of "default" here. In no sense
is it intended to create "default iterators" (whatever that is). Probably
default_iterator_policies is misnamed, and should be called
"passthrough_iterator_policies" or something. In general,
default_iterator_policies is meant to be used as a base class for other
policies, because it provides useful default policy behaviors.

> I dont have any iterator to assign policies to yet.

The policies are supposed to implement the core operations of the iterator
using the Base object. You can, of course, stick the neccessary
functionality in the Base object and use the default policies, as you are
doing, but it seems a little unnatural to me.

> Next I define the simplest iterator required by the
> default_iterator_policies.

Please, don't say that! default_iterator_policies doesn't require an
iterator, and if you define the simplest Base object required, you're not
defining an iterator. Witness counting_iterator_adaptor, which can accept an
integer as a Base object.

> 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
> it were?

If you have a DIR structure, I would use that as the Base object directly,
then write a Policies class which implements the operations on it.

-Dave


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