]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/graph/example/filtered-copy-example.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / graph / example / filtered-copy-example.cpp
CommitLineData
7c673cae 1//=======================================================================
f67539c2 2// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
7c673cae
FG
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 <boost/graph/copy.hpp>
11#include <boost/graph/adjacency_list.hpp>
12#include <boost/graph/filtered_graph.hpp>
13#include <boost/graph/graph_utility.hpp>
14
f67539c2
TL
15template < typename Graph > struct non_zero_degree
16{
17 non_zero_degree() {} // has to have a default constructor!
7c673cae 18
f67539c2 19 non_zero_degree(const Graph& g) : g(&g) {}
7c673cae 20
f67539c2
TL
21 bool operator()(
22 typename boost::graph_traits< Graph >::vertex_descriptor v) const
23 {
24 return degree(v, *g) != 0;
25 }
26 const Graph* g;
7c673cae
FG
27};
28
f67539c2 29int main()
7c673cae 30{
f67539c2
TL
31 using namespace boost;
32 typedef adjacency_list< vecS, vecS, bidirectionalS,
33 property< vertex_name_t, char > >
34 graph_t;
35
36 enum
37 {
38 a,
39 b,
40 c,
41 d,
42 e,
43 f,
44 g,
45 N
46 };
47 graph_t G(N);
48 property_map< graph_t, vertex_name_t >::type name_map = get(vertex_name, G);
49 char name = 'a';
50 graph_traits< graph_t >::vertex_iterator v, v_end;
51 for (boost::tie(v, v_end) = vertices(G); v != v_end; ++v, ++name)
52 name_map[*v] = name;
53
54 typedef std::pair< int, int > E;
55 E edges[] = { E(a, c), E(a, d), E(b, a), E(b, d), E(c, f), E(d, c), E(d, e),
56 E(d, f), E(e, b), E(e, g), E(f, e), E(f, g) };
57 for (int i = 0; i < 12; ++i)
58 add_edge(edges[i].first, edges[i].second, G);
59
60 print_graph(G, name_map);
61 std::cout << std::endl;
62
63 clear_vertex(b, G);
64 clear_vertex(d, G);
65
66 graph_t G_copy;
67 copy_graph(
68 make_filtered_graph(G, keep_all(), non_zero_degree< graph_t >(G)),
69 G_copy);
70
71 print_graph(G_copy, get(vertex_name, G_copy));
72
73 return 0;
7c673cae 74}