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 
11 #ifdef BOOST_MSVC
12 // Without this we get hard errors, not warnings:
13 #pragma warning(disable : 4703)
14 #endif
15 
16 #include <boost/graph/adjacency_list.hpp>
17 #include <boost/graph/iteration_macros.hpp>
18 #include <iostream>
19 
20 enum family
21 {
22     Jeanie,
23     Debbie,
24     Rick,
25     John,
26     Amanda,
27     Margaret,
28     Benjamin,
29     N
30 };
31 
main()32 int main()
33 {
34     using namespace boost;
35     const char* name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
36         "Margaret", "Benjamin" };
37 
38     adjacency_list<> g(N);
39     add_edge(Jeanie, Debbie, g);
40     add_edge(Jeanie, Rick, g);
41     add_edge(Jeanie, John, g);
42     add_edge(Debbie, Amanda, g);
43     add_edge(Rick, Margaret, g);
44     add_edge(John, Benjamin, g);
45 
46     graph_traits< adjacency_list<> >::vertex_iterator i, end;
47     graph_traits< adjacency_list<> >::adjacency_iterator ai, a_end;
48     property_map< adjacency_list<>, vertex_index_t >::type index_map
49         = get(vertex_index, g);
50 
51     BGL_FORALL_VERTICES(i, g, adjacency_list<>)
52     {
53         std::cout << name[get(index_map, i)];
54 
55         if (out_degree(i, g) == 0)
56             std::cout << " has no children";
57         else
58             std::cout << " is the parent of ";
59 
60         BGL_FORALL_ADJ(i, j, g, adjacency_list<>)
61         std::cout << name[get(index_map, j)] << ", ";
62         std::cout << std::endl;
63     }
64     return EXIT_SUCCESS;
65 }
66