on Tue Sep 16 2008, "Robert Dailey"
Hi,
I have the following iterator_facade class:
class PassIterator : public boost::iterator_facade< PassIterator, Pass, boost::forward_traversal_tag > { public: PassIterator();
PassIterator( Effect const& effect );
private: void increment(); Pass& dereference() const;
Pass m_pass;
friend class boost::iterator_core_access; };
Note how my Pass object is stored by-value in my PassIterator class. When I attempt to compile this class, it fails because dereference() is const and it is trying to return a reference to a const member. However, if I make dereference() non-const, it still fails because the base class is calling into PassIterator::dereference() through a const member function as well, so dereference() *must* be const in order to be callable by boost.
How can I overcome this issue? const_cast? mutable? Thanks.
Mutable, it seems to me. Dereference must be a non-mutating operation on the iterator itself. The fact that the referenced object happens to be stored inside the iterator notwithstanding, it is not logically a part of the iterator's value. -- Dave Abrahams BoostPro Computing http://www.boostpro.com