Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-06-13 07:25:13


From: "Damien Fisher" <damien_at_[hidden]>

> > 1. the iterator is an input iterator but not a forward iterator
> > 2. The iterator is a random access iterator that internally stores a
copy
> > of the bool lvalue you would get by dereferencing it.
>
> How would this work? (I don't know what the semantics are for
> dyn_bitset, but I think this code is understandable)
>
> dyn_bitset bs(6); // create bitset of size 6
>
> bs[5] = 0; // set 6th bit to 0
> dyn_bitset::iterator itr1 = bs[5];
> dyn_bitset::iterator itr2 = bs[5];

You can't write that, of course.

> *itr1 = 1; // saves 1 in the iterator
> *itr2 = 0; // saves 0 in the iterator
>
> // itr2 destroyed -- writes 0 to the bitset
> // itr1 destroyed -- writes 1 to the bitset
>
> If the iterator writes the values back upon destruction, then the value
> of bs[5] here will be 1, not 0. This strikes me as really
> weird...surely this isn't standards conforming???

I think it's weird, but might be conforming. Certainly the iterators by
themselves are conforming. I don't think the standard says very much about
the relationship between a container and its iterators. It depends how
strictly you want to read statements such as "begin() returns an iterator
referring to the first element in the container".

-Dave


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