edge-iter-constructor.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //=======================================================================
  2. // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //=======================================================================
  8. #include <boost/config.hpp>
  9. #include <fstream>
  10. #include <boost/graph/adjacency_list.hpp>
  11. #include <boost/graph/graph_utility.hpp>
  12. using namespace boost;
  13. template < typename T >
  14. std::istream & operator >> (std::istream & in, std::pair < T, T > &p) {
  15. in >> p.first >> p.second;
  16. return in;
  17. }
  18. int
  19. main(int argc, const char** argv)
  20. {
  21. typedef adjacency_list <
  22. listS, // Store out-edges of each vertex in a std::list
  23. vecS, // Store vertex set in a std::vector
  24. directedS // The graph is directed
  25. > graph_type;
  26. std::ifstream file_in(argc >= 2 ? argv[1] : "makefile-dependencies.dat");
  27. typedef graph_traits < graph_type >::vertices_size_type size_type;
  28. size_type n_vertices;
  29. file_in >> n_vertices; // read in number of vertices
  30. graph_type
  31. g(n_vertices); // create graph with n vertices
  32. // Read in edges
  33. graph_traits < graph_type >::vertices_size_type u, v;
  34. while (file_in >> u)
  35. if (file_in >> v)
  36. add_edge(u, v, g);
  37. else
  38. break;
  39. assert(num_vertices(g) == 15);
  40. assert(num_edges(g) == 19);
  41. return 0;
  42. }