undirected_dfs: how to get the vectors of edges
<p><strong>NB: The question below is the context of "boost-graph". But the issue is maybe a "c++" issue or "boost-graph" issue.</strong></p>

<p>Using <strong>boost-graph</strong> and <strong>undirected_dfs</strong>, I am trying to get the vectors of edges.</p>

<p>The code print correctly back_edge and tree_edge. </p>

<p>My goal is to retrieve the vectors of edges. For this operation i use a vector of vectors of edges.</p>

<p>So, when a tree_edge is found i store it  in a vector:</p>

<pre><code>edgeVisited.push_back(e);
</code></pre>

<p>When the back_end is found, i store this vector of edges (edgeVisited) in a vector of vectors:</p>

<pre><code>myList.push_back(edgeVisited);
</code></pre>

<p>Just after this operation, i check the size of myList. The result is correct:</p>

<pre><code>std::cout &lt;&lt; "myList size by back_edge: " &lt;&lt; myList.size() &lt;&lt; std::endl;
</code></pre>

<p>After the call to undirected_dfs, i want to get the myList by</p>

<pre><code>std::vector&lt; std::vector&lt;edge_t&gt; &gt; vctr = vis.GetEdges();
</code></pre>

<p>and check it size by:</p>

<pre><code>std::cout &lt;&lt; vctr.size() &lt;&lt; std::endl;
</code></pre>

<p>But the vector is void.</p>

<p><strong>Could you please help me to understand why this vector of vector is null?</strong></p>

<pre><code>Here is the whole code:
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;boost/cstdlib.hpp&gt;
#include &lt;boost/graph/adjacency_list.hpp&gt;
#include &lt;boost/graph/undirected_dfs.hpp&gt;
#include &lt;boost/graph/graphviz.hpp&gt;

using namespace boost;
typedef adjacency_list&lt; 
    vecS, 
    vecS, 
    undirectedS,
    no_property,
    property&lt;edge_color_t, default_color_type&gt; &gt; graph_t;

typedef boost::graph_traits&lt;graph_t&gt;::vertex_descriptor vertex_t;
typedef boost::graph_traits &lt; graph_t&gt;::edge_descriptor edge_t;

struct detect_loops : public boost::dfs_visitor&lt;&gt;
{
    template &lt;class edge_t, class Graph&gt;

    void back_edge(edge_t e, const Graph&amp; g) {
        std::cout &lt;&lt; source(e, g) &lt;&lt; " -- " &lt;&lt; target(e, g) &lt;&lt; "\n";
        edgeVisited.push_back(e);
        myList.push_back(edgeVisited);
        edgeVisited.clear();
        std::cout &lt;&lt; "myList size by back_edge: " &lt;&lt; myList.size() &lt;&lt; std::endl;
    }
    template &lt;class Graph&gt;
    void tree_edge(edge_t e, const Graph&amp; g) {
        std::cout &lt;&lt; "tree_edge: " &lt;&lt; boost::source(e, g) &lt;&lt; " --&gt; " &lt;&lt; boost::target(e, g) &lt;&lt; std::endl;
        edgeVisited.push_back( e );
    }
    //get the vectors.
    std::vector&lt; std::vector&lt;edge_t&gt; &gt;  GetEdges() const { 
        std::cout &lt;&lt; "MyList by GetEdges : " &lt;&lt; myList.size() &lt;&lt; std::endl;
        return myList; 
    }

private:
    std::vector&lt;edge_t&gt; edgeVisited;
    std::vector&lt; std::vector&lt;edge_t&gt; &gt; myList;
};

void make(graph_t &amp;g)
{
    //Create the graph
    boost::add_edge(0, 1, g);
    boost::add_edge(0, 2, g);
    boost::add_edge(1, 3, g);
    boost::add_edge(2, 3, g);
    boost::add_edge(2, 4, g);
    boost::add_edge(3, 5, g);
    boost::add_edge(4, 5, g);
    //print the graph
    std::ofstream f("d:\\tmp\\dot\\s13.dot");
    boost::write_graphviz(f, g);
    std::system(std::string("dot -Tsvg -Grankdir=LR -Nfontsize=24 d:\\tmp\\dot\\s13.dot &gt; d:\\tmp\\dot\\s13.svg").c_str());
}

int main(int, char*[])
{
    graph_t g;
    make(g);

    detect_loops vis;
    undirected_dfs(g, root_vertex(vertex_t(0)).visitor(vis) .edge_color_map(get(edge_color, g)));
    std::vector&lt; std::vector&lt;edge_t&gt; &gt; vctr = vis.GetEdges();
    std::cout &lt;&lt; vctr.size() &lt;&lt; std::endl;

    return boost::exit_success;
}
</code></pre>

<p>Thanks</p>