]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/iteration_macros.cpp
1 //=======================================================================
2 // Copyright 2001 Indiana University.
3 // Author: Jeremy G. Siek
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 //=======================================================================
11 #include <boost/graph/adjacency_list.hpp>
12 #include <boost/graph/iteration_macros.hpp>
15 enum family
{ Jeanie
, Debbie
, Rick
, John
, Amanda
, Margaret
, Benjamin
, N
};
19 using namespace boost
;
20 const char *name
[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
21 "Margaret", "Benjamin"
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
);
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
);
37 BGL_FORALL_VERTICES(i
, g
, adjacency_list
<>) {
38 std::cout
<< name
[get(index_map
, i
)];
40 if (out_degree(i
, g
) == 0)
41 std::cout
<< " has no children";
43 std::cout
<< " is the parent of ";
45 BGL_FORALL_ADJ(i
, j
, g
, adjacency_list
<>)
46 std::cout
<< name
[get(index_map
, j
)] << ", ";
47 std::cout
<< std::endl
;