I try to add Vertex and Edge data with bundled properties. I am modifying the sample program interior_property_map.cpp to learn how to access the bundled properties, but I don't know how to fix my compile error. What is the right way to access the bundled properties for edge? Source code is: #include <boost/config.hpp> #include <iostream> #include <algorithm> #include <boost/graph/adjacency_list.hpp> #include <boost/property_map.hpp> using namespace std; using namespace boost; struct VertexData { int x; int y; }; struct EdgeData { int weight; }; template <class EdgeIter, class Graph> void who_owes_who(EdgeIter first, EdgeIter last, const Graph& G) { // Access the propety acessor type for this graph while (first != last) { // fail to compile here!!! cout << G[source(*first, G)].x << "," << G[source(*first, G)].y << " joins " << G[target(*first, G)].x << "," << G[target(*first, G)].y << " weight " << G[edge(*first)].weight << endl; ++first; } } int main() { // Create the graph, and specify that we will use store the data. typedef adjacency_list<vecS, vecS, directedS, VertexData, EdgeData> MyGraphType; typedef pair<int, int> Pair; // from <utility> Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4), Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1), Pair(3,4), Pair(4,0), Pair(4,1) }; MyGraphType G(5); for (int i=0; i<11; ++i) add_edge(edge_array[i].first, edge_array[i].second, G); G[0].x = 0; G[0].y = 0; G[1].x = 1; G[1].y = 1; G[2].x = 2; G[2].y = 2; G[3].x = 3; G[3].y = 3; G[4].x = 4; G[4].y = 4; // store weights in edges graph_traits <MyGraphType>::edge_iterator ei, eend; int i = 0; for (tie(ei, eend) = edges(G); ei != eend; ++ei) { G[*ei].weight = i++; cout << "G[e] weight " << G[*ei].weight << endl; } who_owes_who(edges(G).first, edges(G).second, G); cout << endl; return 0; } Compile error is: gcc-C++-action /home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o /home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp: In function `void who_owes_who(EdgeIter, EdgeIter, const Graph&) [with EdgeIter = boost::detail::adj_list_edge_iterator<boost::counting_iterator<size_t, boost::use_default, boost::use_default>, boost::detail::out_edge_iter<__gnu_cxx::__normal_iterator<boost::detail::sep_<size_t, boost::property<boost::edge_bundle_t, EdgeData, boost::no_property> >*, std::vector<boost::detail::sep_<size_t, boost::property<boost::edge_bundle_t, EdgeData, boost::no_property> >, std::allocator<boost::detail::sep_<size_t, boost::property<boost::edge_bundle_t, EdgeData, boost::no_property> > > > >, size_t, boost::detail::edge_desc_impl<boost::directed_tag, size_t>, ptrdiff_t>, boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexData, EdgeData, boost::no_property, boost::listS> >, Graph = main()::MyGraphType]': /home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:113: instantiated from here /home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:64: error: no matching function for call to `edge(boost::detail::edge_desc_impl<boost::directed_tag, size_t>)' set -e "g++" -c -Wall -ftemplate-depth-255 -g -O0 -Wno-inline -I"../../../bin/boost/libs/graph/example" -I "/home/tcma/cpp/boost_1_32_0" -o "/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o" "/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp" "/usr/bin/objcopy" --set-section-flags .debug_str=contents,debug "/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o" ... ===== TingChong Ma ______________________________________________________________________ Post your free ad now! http://personals.yahoo.ca
TC MA wrote:
G[source(*first, G)].y << " joins " << G[target(*first, G)].x << "," << G[target(*first, G)].y << " weight " << G[edge(*first)].weight << endl; ++first;
What's the 'edge' function and why do you call it? What about just '*first', which gives you an edge_description already? - Volodya
participants (2)
-
TC MA
-
Vladimir Prus