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;
};
I cannot use this ProxyIterator with a boost::reverse_iterator adaptor because the implementation of reverse_iterator's dereference dereferences a temporary:
// from reverse_iterator.hpp
typename super_t::reference dereference() const { return *boost::prior(this->base()); }
and in ProxyIterator, this dereference returns a reference to an internal member, m_value, that will immediately vanish out of existence. Bummer.
What if reverse_iterator carried as member the decremented iterator instead of decrementing to a temporary on a dereference?
In the current reverse_iterator implementation, decrement must behave properly on an end iterator, but not on a begin iterator. Can a begin iterator be decremented and still used for comparison purposes?
-seb