Re: [Boost-users] [iterator] reverse_iterator from iterators thatreturn references to data in self.
"David Abrahams"
"Seb Martel"
writes: Hello,
given something like:
class ProxyIterator : public boost::iterator_facade
{ 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
"Seb Martel"
Is http://boost.org/libs/iterator/doc/new-iter-concepts.html making any progress ?
Not as far as I know. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Seb Martel