
Hi,
I'm stuck trying to use iterator_adaptor from the CVS head. I simply want
to derive a non-const iterator from a const one derived from
iterator_facade, as shown in the code below. When I compile it with VC7.1,
the line marked "/* *ERROR* */" generates one of those impenetratable error
messages that starts with:
cannot convert from 'const Node' to
'boost::iterator_facade
boost_const_iterator;
class const_iterator : public boost_const_iterator { public: const_iterator() {} const_iterator(const iterator& it) : m_pNode(it.base().m_pNode) {} explicit const_iterator(const Node* pNode) : m_pNode(pNode) {} friend class iterator; friend class boost::iterator_core_access; private: // Interface required by iterator_facade: reference dereference() const { return *m_pNode; } void increment() { m_pNode = m_pNode->next(); } void decrement() { m_pNode = m_pNode->prev(); } bool equal(const_iterator it) const { return m_pNode == it.m_pNode; } protected: const Node* m_pNode; }; // Read-write, bidirectional iterator, // adapted from const_iterator: typedef boost::iterator_adaptor< iterator, const_iterator, Node /* *ERROR* */
iterator_base;
class iterator : public iterator_base { public: iterator() {} explicit iterator(Node* pNode) : iterator_base(const_iterator(pNode)) {} }; const_iterator begin() const { return const_iterator(m_pChild); } const_iterator end() const { return const_iterator(NULL); } iterator begin() { return iterator(m_pChild); } iterator end() { return iterator(NULL); } private: Node* m_pChild; Node* m_pPrev; Node* m_pNext; }; /* ========================= Code Ends ========================= */