Boost logo

Boost Users :

From: Seb Martel (smartel_at_[hidden])
Date: 2006-07-14 20:19:35


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;
};
 
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
 
 
 


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