Boost logo

Boost :

From: Sylvain Pion (Sylvain.Pion_at_[hidden])
Date: 2003-05-11 13:30:12


On Sun, May 11, 2003 at 01:47:00PM -0400, David Abrahams wrote:
> > I have a suggestion for another "orthogonal" feature of iterators, which is
> > available for plain pointers : NULL. More precisely, the fact that the
> > default initialized iterator is a unique (singular) value which you can
> > reliably test equality with.
> >
> > It is very useful to have this capability : in the CGAL library, we store
> > the nodes of a graph in containers. Graphs are a bunch of nodes storing
> > pointers/iterators to each other. Having a value like NULL is very useful
> > there, because the alternative is either to allocate a specific object
> > whose iterator you use for this purpose (but it requires access to the
> > associated container to test with, which is painful), or storing a bool,
> > which is a waste of memory.
> >
> > I don't know if these issues arise in the BGL as well.
> >
> > I think this feature doesn't make sense for all iterators, especially for
> > Input and Output iterators. However, for iterators connected with
> > containers, they are usually trivial to provide because the iterator
> > usually stores a pointer, which can then be default initialized to NULL.
> >
> > In the case of CGAL, it would simply allow us to re-use the standard
> > containers for storing our graphs, while right now we re-implement
> > containers...
>
> What, specifically, would allow you to re-use the standard
> containers? I'm looking for a statement along the lines of, "if ...
> then we could re-use the standard containers".
>
> I'm guessing "..." is something like, "if default-constructed standard
> container iterators were non-singular and guaranteed to be unequal to
> any iterator obtained by other means".

That would be something more like "if default-constructed standard container
iterators were non-singular and guaranteed to be unequal to any iterator
obtained by other means, and compare equal to any default-constructed
iterator."

I.e. the default constructed value must be unique (as far as operator== is
concerned).

> > Another feature (less important but connected to the previous one) that
> > pointers have and iterators don't : automatic conversion to bool.
> >
> > What do you think ?
>
> It sounds like a useful concept, if I've understood you correctly.
>
> At the same time, I doubt it belongs in our proposal: we don't say
> anything about containers (except vector<bool>, and then only in the
> rationale). You should write a proposal for extension and submit it
> to the commitee if you care about this. It should be easy, compared
> to the iterator adaptors/categories proposal.

OK. I'll think about writing something.

-- 
Sylvain

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