• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iostream>
10 #include <vector>
11 #include <string>
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/tuple/tuple.hpp>
14 enum family
15 {
16     Jeanie,
17     Debbie,
18     Rick,
19     John,
20     Amanda,
21     Margaret,
22     Benjamin,
23     N
24 };
main()25 int main()
26 {
27     using namespace boost;
28     const char* name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
29         "Margaret", "Benjamin" };
30 
31     adjacency_list<> g(N);
32     add_edge(Jeanie, Debbie, g);
33     add_edge(Jeanie, Rick, g);
34     add_edge(Jeanie, John, g);
35     add_edge(Debbie, Amanda, g);
36     add_edge(Rick, Margaret, g);
37     add_edge(John, Benjamin, g);
38 
39     graph_traits< adjacency_list<> >::vertex_iterator i, end;
40     graph_traits< adjacency_list<> >::adjacency_iterator ai, a_end;
41     property_map< adjacency_list<>, vertex_index_t >::type index_map
42         = get(vertex_index, g);
43 
44     for (boost::tie(i, end) = vertices(g); i != end; ++i)
45     {
46         std::cout << name[get(index_map, *i)];
47         boost::tie(ai, a_end) = adjacent_vertices(*i, g);
48         if (ai == a_end)
49             std::cout << " has no children";
50         else
51             std::cout << " is the parent of ";
52         for (; ai != a_end; ++ai)
53         {
54             std::cout << name[get(index_map, *ai)];
55             if (boost::next(ai) != a_end)
56                 std::cout << ", ";
57         }
58         std::cout << std::endl;
59     }
60     return EXIT_SUCCESS;
61 }
62