How do you use boost iterators

Posted by Neil G on Stack Overflow See other posts from Stack Overflow or by Neil G
Published on 2010-05-13T20:38:53Z Indexed on 2010/05/13 21:04 UTC
Read the original article Hit count: 213

Filed under:
|

It worked, and then I added the typedefs so that I could have a const_sparse_iterator as well. Now, when I compile this and try to use sparse_iterator, it says:

/Users/neilrg/nn/src/./core/sparse_vector.h:331: error: invalid use of incomplete type 'struct sparse_vector<A>::sparse_iterator'

Here's the code. More code here.

tempalte<typename T>
class sparse_vector {
// There is more code at my previous question, but this might be enough...?
private:
    template<typename base_type>
    class sparse_iterator_private
        : public boost::iterator_adaptor<
          sparse_iterator_private<base_type>    // Derived
          , base_type                           // Base
          , value_type                          // Value
          , boost::random_access_traversal_tag  // CategoryOrTraversal
          > {
    private:
        struct enabler {};  // a private type avoids misuse

    public:
        sparse_iterator_private()
            : sparse_iterator_private<base_type>::iterator_adaptor_(0) {}

        explicit sparse_iterator_private(typename array_type::iterator&& p)
            : sparse_iterator_private<base_type>::iterator_adaptor_(p) {}

    private:
        friend class boost::iterator_core_access;

        reference dereference() const { return this->base()->value; }
    };

public:
    typedef sparse_iterator_private<typename array_type::iterator> sparse_iterator;
    typedef sparse_iterator_private<typename array_type::const_iterator> const_sparse_iterator;
};

© Stack Overflow or respective owner

Related posts about boost

Related posts about iterator