]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/iteration_macros.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / graph / example / iteration_macros.cpp
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
10
11 #include <boost/graph/adjacency_list.hpp>
12 #include <boost/graph/iteration_macros.hpp>
13 #include <iostream>
14
15 enum family { Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };
16
17 int main()
18 {
19 using namespace boost;
20 const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
21 "Margaret", "Benjamin"
22 };
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
32 graph_traits<adjacency_list <> >::vertex_iterator i, end;
33 graph_traits<adjacency_list <> >::adjacency_iterator ai, a_end;
34 property_map<adjacency_list <>, vertex_index_t>::type
35 index_map = get(vertex_index, g);
36
37 BGL_FORALL_VERTICES(i, g, adjacency_list<>) {
38 std::cout << name[get(index_map, i)];
39
40 if (out_degree(i, g) == 0)
41 std::cout << " has no children";
42 else
43 std::cout << " is the parent of ";
44
45 BGL_FORALL_ADJ(i, j, g, adjacency_list<>)
46 std::cout << name[get(index_map, j)] << ", ";
47 std::cout << std::endl;
48 }
49 return EXIT_SUCCESS;
50 }