Custom InputIterator for Boost graph (BGL)

Posted by Shadow on Stack Overflow See other posts from Stack Overflow or by Shadow
Published on 2010-05-18T09:29:09Z Indexed on 2010/05/18 9:30 UTC
Read the original article Hit count: 116

Filed under:
|
|
|

Hi,

I have a graph with custom properties to the vertices and edges. I now want to create a copy of this graph, but I don't want the vertices to be as complex as in the original. By this I mean that it would suffice that the vertices have the same indices (vertex_index_t) as they do in the original graph.
Instead of doing the copying by hand I wanted to use the copy-functionality of boost::adjacency_list (s. http://www.boost.org/doc/libs/1_37_0/libs/graph/doc/adjacency_list.html):

template <class EdgeIterator>
adjacency_list(EdgeIterator first, EdgeIterator last,
           vertices_size_type n,
           edges_size_type m = 0,
           const GraphProperty& p = GraphProperty())

The description there says:

The EdgeIterator must be a model of InputIterator. The value type of the EdgeIterator must be a std::pair, where the type in the pair is an integer type. The integers will correspond to vertices, and they must all fall in the range of [0, n).

Unfortunately I have to admit that I don't quite get it how to define an EdgeIterator that is a model of InputIterator.
Here's what I've succeded so far:

template< class EdgeIterator, class Edge >
class MyEdgeIterator// : public input_iterator< std::pair<int, int> > 
{
public:
        MyEdgeIterator() {}; 

        MyEdgeIterator(EdgeIterator& rhs) : actual_edge_it_(rhs) {}; 

        MyEdgeIterator(const MyEdgeIterator& to_copy) {}; 

        bool operator==(const MyEdgeIterator& to_compare)
        {   
                return actual_edge_it_ == to_compare.actual_edge_it_;
        }   

        bool operator!=(const MyEdgeIterator& to_compare)
        {   
                return !(*this == to_compare);
        }   

        Edge operator*() const
        {   
                return *actual_edge_it_;
        }

        const MyEdgeIterator* operator->() const;
        MyEdgeIterator& operator ++()
        {   
                ++actual_edge_it_;
                return *this;
        }   

        MyEdgeIterator operator ++(int)
        {   
                MyEdgeIterator<EdgeIterator, Edge> tmp = *this;
                ++*this;
                return tmp;
        }

private:
        EdgeIterator& actual_edge_it_;
}

However, this doesn't work as it is supposed to and I ran out of clues.
So, how do I define the appropriate InputIterator?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost