Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2003-07-15 20:10:30


"Marshall Clow" <marshall_at_[hidden]> wrote in message
news:p06001a06bb3a461d34fc@[129.46.153.123]...
> "Joe Gottman" <jgottman_at_[hidden]> wrote:
> >Suppose I have a vector<Foo *> and I want to use indirect_iterator to
create
> >an iterator that allows the user to read but not modify the objects
pointed
> >to by elements of the vector. In other words, I want to do the
following:
> > typedef /*whatever */ my_iterator;
> > my_iterator it(theVector.begin());
> > const Foo &foo = *it;
> >
> > But I want
> > *it = Foo();
> >to fail. Also, if possible I would like this new type to interact with
> > indirect_iterator<vector<Foo *>::iterator>
> >in the expected way.
> >
> > I'm sure this is possible, but the documentation doesn't really say
how to
> >do it.
>
> is there some reason you can't use const_iterator?
>

    const_iterator doesn't do what I want. Consider the following code:
          vector<Foo *>::const_iterator theIterator = myVector.begin();
          **theIterator = Foo();

This code should compile fine, since it's not changing the value of
*theIterator. This is why most smart pointers have operator* and operator->
defined as const member functions.

Joe Gottman


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