iterator_facade with incomplete type as Value argument
I've tried writing an iterator with iterator_facade that returns itself as the result of dereference, but the Value template argument requires a complete type because it tries to make a difference between returning by value or reference if Value is_pod (as far as I understand). #include <boost/iterator/iterator_facade.hpp> class iter : public boost::iterator_facade< iter, iter, boost::forward_traversal_tag > { public: void fancy_non_iterator_member(); private: friend class boost::iterator_core_access; void increment() { } bool equal(iter const& other) const { return true; } iter& dereference() const { return const_cast<Derived&>(static_cast<const Derived&>(*this)); } }; Is this the intended behavior of iterator_facade? Is there some workaround? Would such an iterator actually be conforming? -- Philipp Moeller GeometryFactory
Philipp Moeller <philipp.moeller@geometryfactory.com> writes:
I've tried writing an iterator with iterator_facade that returns itself as the result of dereference, but the Value template argument requires a complete type because it tries to make a difference between returning by value or reference if Value is_pod (as far as I understand).
#include <boost/iterator/iterator_facade.hpp>
class iter : public boost::iterator_facade< iter, iter, boost::forward_traversal_tag > { public: void fancy_non_iterator_member(); private: friend class boost::iterator_core_access;
void increment() { }
bool equal(iter const& other) const { return true; }
iter& dereference() const { return const_cast<Derived&>(static_cast<const Derived&>(*this)); } };
Is this the intended behavior of iterator_facade? Is there some workaround? Would such an iterator actually be conforming?
There is a mistake in the preceding post. iter::dereference should be defined as: iter& dereference() const { return const_cast<iter&>(static_cast<const iter&>(*this)); }
participants (1)
-
Philipp Moeller