iteration_macros.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //=======================================================================
  2. // Copyright 2001 Indiana University.
  3. // Author: Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #include <boost/config.hpp>
  10. #ifdef BOOST_MSVC
  11. // Without this we get hard errors, not warnings:
  12. #pragma warning(disable:4703)
  13. #endif
  14. #include <boost/graph/adjacency_list.hpp>
  15. #include <boost/graph/iteration_macros.hpp>
  16. #include <iostream>
  17. enum family { Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };
  18. int main()
  19. {
  20. using namespace boost;
  21. const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
  22. "Margaret", "Benjamin"
  23. };
  24. adjacency_list <> g(N);
  25. add_edge(Jeanie, Debbie, g);
  26. add_edge(Jeanie, Rick, g);
  27. add_edge(Jeanie, John, g);
  28. add_edge(Debbie, Amanda, g);
  29. add_edge(Rick, Margaret, g);
  30. add_edge(John, Benjamin, g);
  31. graph_traits<adjacency_list <> >::vertex_iterator i, end;
  32. graph_traits<adjacency_list <> >::adjacency_iterator ai, a_end;
  33. property_map<adjacency_list <>, vertex_index_t>::type
  34. index_map = get(vertex_index, g);
  35. BGL_FORALL_VERTICES(i, g, adjacency_list<>) {
  36. std::cout << name[get(index_map, i)];
  37. if (out_degree(i, g) == 0)
  38. std::cout << " has no children";
  39. else
  40. std::cout << " is the parent of ";
  41. BGL_FORALL_ADJ(i, j, g, adjacency_list<>)
  42. std::cout << name[get(index_map, j)] << ", ";
  43. std::cout << std::endl;
  44. }
  45. return EXIT_SUCCESS;
  46. }