title: On-the-fly calculation of edges in Boost Graph Library possible?
body: <p>In my application I have some kind of graph where every node/vertex
  can be connected to each other but actual connection is determined
  at runtime.</p>
  
  <p>Of course this is trivial to implement by iterating
  over all existing vertices and connecting them to the last one
  I've added to the graph and using a filtered graph at runtime
  to decide of the connection still persists.</p>
  
  <p>Purpose is to use BFS or DFS or other algorithms provided by BGL.</p>
  
  <p>Is there any other approach to get that task done more efficiently?
  By example: Adding all(!) vertices at initialization and having some
  kind of callback which checks for an edge at runtime?</p>
  
  <p>That's what how I tried to solve it but that one doesn't work:</p>
  
  <pre><code>#include &lt;boost/graph/adjacency_matrix.hpp&gt;
  #include &lt;boost/graph/graph_utility.hpp&gt;
  struct VD { };
  struct ED { };
  
  struct Graph : boost::adjacency_matrix&lt;boost::directedS, VD, ED&gt;
  {
      Graph() : boost::adjacency_matrix&lt;boost::directedS, VD, ED&gt;(4) { }
      //=================================================================
      // Functions required by the AdjacencyMatrix concept
      template &lt;typename D, typename VP, typename EP, typename GP, typename A&gt;
      std::pair&lt;typename adjacency_matrix&lt;D,VP,EP,GP,A&gt;::edge_descriptor, bool&gt;
      edge(typename adjacency_matrix&lt;D,VP,EP,GP,A&gt;::vertex_descriptor u,
          typename adjacency_matrix&lt;D,VP,EP,GP,A&gt;::vertex_descriptor v,
          const adjacency_matrix&lt;D,VP,EP,GP,A&gt;&amp; g)
      {
          // Connect vertex 1 and 2
          bool exists = (u == 1 &amp;&amp; v == 2);
  
          typename boost::adjacency_matrix&lt;D,VP,EP,GP,A&gt;::edge_descriptor
              e(exists, u, v, boost::detail::get_edge_property(g.get_edge(u,v)));
  
          return std::make_pair(e, exists);
      }
  };
  
  int main() {
      Graph g;
      print_graph(g);
  
      std::vector&lt;int&gt; component(num_vertices(g));
      int num = boost::connected_components(g, &amp;component[0]);
  }
  </code></pre>
  
  <p>Any pointers would be appreciated!</p>