Ticket #1021: bug_report_example_reverse_graph.cpp

File bug_report_example_reverse_graph.cpp, 3.0 KB (added by anonymous, 15 years ago)
Line 
1/// This is an example to demonstrate a problem I encountered with the
2/// Boost Graph Library's (BGL) make_iterator_property_map when used
3/// in conjunction with my own graph that has its property_map
4/// specialization for vertex_index_t define the const_type as a true
5/// const type.
6///
7/// Is there a reason that make_iterator_property_map takes its second
8/// argumant "by value" rather than "by referenc"e as the property_map
9/// constructor does? This seems to cause an extra copy construction
10/// to be performed that results in a non-const type which then does
11/// does not match the property_map's constructor resulting in a
12/// compilation error on GCC.
13
14#include "bug_report_example_skeleton.hpp"
15#include <boost/graph/reverse_graph.hpp>
16// #include "reverse_graph.hpp"
17
18void
19bug_report_example_reverse_graph(MyGraph::Graph& g)
20{
21 typedef boost::reverse_graph<MyGraph::Graph, MyGraph::Graph&> ReverseMyGraph;
22 /// The following does not compile because reverse_graph assumes
23 /// that the BidirectionalGraph template argument will have an
24 /// edge_property_type and a vertex_property_type. A user defined
25 /// graph that has been adapted by providing a specialization for
26 /// graph_traits and the other associated code may not have these
27 /// types as in this case.
28 ///
29 /// Looking at the code it seems these are only being used to
30 /// allow property_map's to be selected. An alternative way oif
31 /// achieving this is for reverse_graph to provide a
32 /// specialization for property_map that simply defines its
33 /// internals in terms of the base graph's property_map
34 /// specialization. This also simplifies the other code in
35 /// reverse_graph that is currently present to support
36 /// property_map selection.
37 ReverseMyGraph reverse_g = boost::make_reverse_graph(g);
38
39 /// After fixing the above problem the following does not work
40 /// because the reverse_graph's definition for num_vertices
41 /// specifies the return type in terms of the base graphs
42 /// vertices_size_type. For a user defined graph that has been
43 /// adapted it may not have such a type as in this case.
44 ///
45 /// A solution is to change reverse_graph's num_vertices to use
46 /// graph_traits to obtain the type. This same problem exists on a
47 /// couple of other functions.
48 num_vertices(reverse_g);
49
50 /// To be consistent some of the other functions need to specify
51 /// both arguments for reverse_graph rather then letting the
52 /// second one default.
53
54 /// An ammended reverse_graph.hpp is provided that has these
55 /// changes and works with this example. I am not sure if some of
56 /// the property_map related code that is deleted is needed for
57 /// other reasons. It seems that just forwarding the property_map
58 /// of the reverse graph should avoid the need to provide these
59 /// other types that are used by the non-specialized version of
60 /// property_map. By providing an explicit specialization for
61 /// reverse_graph I think these will never be used.
62}