Ticket #5779: bgl.cc

File bgl.cc, 1.7 KB (added by public@…, 11 years ago)

code example of bug

Line 
1#include <cstring> // for std::size_t
2#include <iostream>
3#include <string>
4using namespace std;
5
6#include <boost/graph/adjacency_list.hpp>
7#include <boost/graph/breadth_first_search.hpp>
8#include <boost/graph/depth_first_search.hpp>
9#include <boost/graph/visitors.hpp>
10using namespace boost;
11
12typedef boost::property<boost::vertex_name_t, std::string,
13 boost::property<boost::vertex_index_t,
14 std::size_t> > VertexProperties;
15typedef boost::adjacency_list<boost::listS,
16 boost::listS,
17 boost::bidirectionalS,
18 VertexProperties> Graph; // Graph object type
19
20typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
21typedef boost::graph_traits<Graph>::edge_descriptor Edge;
22
23typedef boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
24typedef boost::graph_traits<Graph>::adjacency_iterator adjacency_iterator;
25typedef Graph::inv_adjacency_iterator inv_adjacency_iterator;
26
27typedef boost::property_map<Graph,boost::vertex_name_t>::type
28 vertex_name_map_t;
29
30class VisitorClass : public dfs_visitor<> {
31 public:
32 VisitorClass() {}
33
34 template <typename Edge, typename Graph>
35 void back_edge(Edge, const Graph&) const {
36 cout << "back edge" << endl;
37 }
38};
39
40int
41main() {
42 Graph g;
43 vertex_name_map_t vertex_names = get(vertex_name, g);
44 Vertex v = add_vertex(g);
45 Vertex u = add_vertex(g);
46
47 vertex_names[v] = string("v");
48 vertex_names[u] = string("u");
49
50 bool inserted;
51 tie(tuples::ignore, inserted) = add_edge(v, u, g);
52 assert(inserted);
53
54 VisitorClass vst;
55 depth_first_search(g, visitor(vst));
56 // Should not print "back edge", but does.
57
58 return 0;
59}