Boost logo

Boost Users :

From: Seb Martel (smartel_at_[hidden])
Date: 2006-07-15 12:50:41


"David Abrahams" <dave_at_[hidden]> wrote in message
news:<uwtafgdi0.fsf_at_[hidden]>...
> "Seb Martel" <smartel_at_[hidden]> writes:
>
> > Hello,
> >
> > given something like:
> >
> > class ProxyIterator
> > : public boost::iterator_facade<ProxyIterator, Costly,
boost::random_access_traversal_tag>
> > {
> > public:
> > ProxyIterator(FactoryOfCostly* pF, int i ) : m_pFactory( pF ),
m_index( i )
> > {}
> > private:
> > friend class boost::iterator_core_access;
> > void decrement() {--m_index;}
> > // ... and others
> >
> > Costly& dereference() const
> > {
> > m_value = m_pFactory->MakeCostlyAtIndex( m_index );
> > return m_value;
> > }
> > private:
> > FactoryOfCostly* m_pFactory;
> > int m_index;
> > mutable Costly m_value;
> > };
>
> You might need to do something to prevent this from being reported as
> a valid random access (or even forward) iterator. 24.1.3:
>
> --- If a and b are both dereferenceable, then a == b if and only if *a
> and *b are the same object.
>

As in &(*a) == &(*b) ? That's just cruel. But then again, vector<bool>
comes to mind... Which reminds me:

Is http://boost.org/libs/iterator/doc/new-iter-concepts.html making
any progress ?

>
> You could build a reverse_iterator like the one you propose by storing
> the inner iterator within a boost::optional wrapper, and only
> initializing it upon dereference.
>

I might just name it the DamnYou2413ReverseIterator.

Tx!

-seb


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