[BGL] Property map question

What determines when boost::get(Graph, vertex_myproperty_t) returns a boost::property_map<graph_t, vertex_myproperty>::type vs. a ::const_type? Suppose: enum vertex_myproperty_t { vertex_myproperty = 12345}; BOOST_INSTALL_PROPERTY(vertex,myproperty); typedef property<vertex_myproperty_t, MyPropertyObject, ....> vertex_properties_t; typedef adjacency_list<vecS,vecS,bidirectionalS, vertex_properties_t> graph_t; typedef property_map<graph_t, vertex_myproperty_t>::type vertex_myproperty_map_t; graph_t Graph;

Sorry - my previous post got cut in half somewhere in transit. This is a reposting: What determines when boost::get(Graph, vertex_myproperty_t) returns a boost::property_map<graph_t, vertex_myproperty>::type vs. a ::const_type? Suppose: enum vertex_myproperty_t { vertex_myproperty = 12345}; BOOST_INSTALL_PROPERTY(vertex,myproperty); typedef property<vertex_myproperty_t, MyPropertyObject, ....> vertex_properties_t; typedef adjacency_list<vecS,vecS,bidirectionalS, vertex_properties_t> graph_t; typedef property_map<graph_t, vertex_myproperty_t>::type vertex_myproperty_map_t; graph_t Graph;

Strange... One last attempt, this time posting through the Yahoo Groups interface and not directly to gmane.comp.lib.boost.user... Sorry - my previous post got cut in half somewhere in transit. This is a reposting: What determines when boost::get(Graph, vertex_myproperty_t) returns a boost::property_map<graph_t, vertex_myproperty>::type vs. a ::const_type? Suppose: enum vertex_myproperty_t { vertex_myproperty = 12345}; BOOST_INSTALL_PROPERTY(vertex,myproperty); typedef property<vertex_myproperty_t, MyPropertyObject, ....> vertex_properties_t; typedef adjacency_list<vecS,vecS,bidirectionalS, vertex_properties_t> graph_t; typedef property_map<graph_t, vertex_myproperty_t>::type vertex_myproperty_map_t; graph_t Graph; vertex_myproperty_map_t MyMap = get(vertex_myproperty, Graph); ^--- this works as I expected. However, if I try to get a copy of my property map this way inside a dfs visitor method, my compiler tells me that there's no suitable conversion from property_map<graph_t, vertex_myproperty_t>::const_type to property_map<graph_t, vertex_myproperty_t>::type (IA32 6.0 Intel compiler). For performance reasons, I should probably just pass a reference the visitor on construction and be done with it for the duration of the algorithm. But why is the compiler hassling me on this? What am I missing? Thanks - Chris

Hi Chris, On Sun, 15 Sep 2002, Chris Russell wrote: cdr> What determines when boost::get(Graph, vertex_myproperty_t) returns a cdr> boost::property_map<graph_t, vertex_myproperty>::type vs. a cdr> ::const_type? The constness of the graph object that is passed to get(). cdr> vertex_myproperty_map_t MyMap = get(vertex_myproperty, Graph); cdr> cdr> ^--- this works as I expected. However, if I try to get a copy of my cdr> property map this way inside a dfs visitor method, my compiler tells cdr> me that cdr> there's no suitable conversion from property_map<graph_t, cdr> vertex_myproperty_t>::const_type to property_map<graph_t, cdr> vertex_myproperty_t>::type (IA32 6.0 Intel compiler). You've got a const graph object inside the visitor, so you need to use the const property map. Cheers, Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------

Okay - I think I understand this. Since posting I've re-read the property map documentation online and in the book and am still confused about several points (forgive me ignorance - I'm learning a lot of new concepts (in the canonical sense) at once). Will you help me with these follow-up questions please: Assertions: (please validate) 1. a property map maps some type (an enum or struct tag) to some other type. 2. a property map declaration may contain nested property map declarations but this does not reflect a hierarchy - it's just a template trick. Effectively the property maps are peers. 3. graph containers like adjacency list will internally create a new value_type object upon insertion of a vertex (in the case of a vertex property map) and an edge (in the case of an edge property map). Assuming the above assertions are correct, I'm still confused about several points: 1. a boost::get call to return either a property_map<x,y>::type or property_map<x,y>::const_type by value? I think yes. The question is does return by value also copy all the value_type's? I'm guessing not because this would be a huge performance hit. Just the property map itself is copied. Correct? 2. In the case of my algorithm visitor, I am passed a const reference to a graph that will result in a boost::get returning a const_type a property map. I can understand that changing the value_type's of an arbitrary property map could potentially screw up an algorithm (if the algorithm is using the specific property that I am trying to write). Is this why the graph passed to the visitor is const? In the case where I need to write an internal property map that is not being used by the specific algorithm (in the case of my dfs search, dfs is using the vertex color and I want to write another, distinct internal property map that I have registered with my graph class), I should pass a reference to the specific map into the constructor of the visitor? Thank you for your help Jeremy. - Regards Chris "Jeremy Siek" <jsiek@cs.indiana.edu> wrote in message news:Pine.GSO.4.44.0209152139410.629-100000@zaphod.osl.iu.edu...
Hi Chris,
On Sun, 15 Sep 2002, Chris Russell wrote: cdr> What determines when boost::get(Graph, vertex_myproperty_t) returns a cdr> boost::property_map<graph_t, vertex_myproperty>::type vs. a cdr> ::const_type?
The constness of the graph object that is passed to get().
cdr> vertex_myproperty_map_t MyMap = get(vertex_myproperty, Graph); cdr> cdr> ^--- this works as I expected. However, if I try to get a copy of my cdr> property map this way inside a dfs visitor method, my compiler tells cdr> me that cdr> there's no suitable conversion from property_map<graph_t, cdr> vertex_myproperty_t>::const_type to property_map<graph_t, cdr> vertex_myproperty_t>::type (IA32 6.0 Intel compiler).
You've got a const graph object inside the visitor, so you need to use the const property map.
Cheers, Jeremy
---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------

Hi Chris, On Mon, 16 Sep 2002, Chris Russell wrote: cdr> Okay - I think I understand this. Since posting I've re-read the cdr> property map documentation online and in the book and am still cdr> confused about several points (forgive me ignorance - I'm learning a cdr> lot of new concepts (in the canonical sense) at once). Will you help cdr> me with these follow-up questions please: cdr> cdr> Assertions: (please validate) cdr> cdr> 1. a property map maps some type (an enum or struct tag) to some other cdr> type. No, a propery map is a map from a set of key objects to a set of value objects. What you are probably thinking about is the boost::get() function that returns a property map for a given graph and property tag. Perhaps it is a little confusing that you use a different overload of boost::get() on the property map itself. cdr> 2. a property map declaration may contain nested property map cdr> declarations but this does not reflect a hierarchy - it's just a cdr> template trick. Effectively the property maps are peers. Hmm, the above statement doesn't make much sense to me. cdr> 3. graph containers like adjacency list will internally create a new cdr> value_type object upon insertion of a vertex (in the case of a vertex cdr> property map) and an edge (in the case of an edge property map). Yes. cdr> Assuming the above assertions are correct, I'm still confused about cdr> several points: cdr> cdr> 1. a boost::get call to return either a property_map<x,y>::type or cdr> property_map<x,y>::const_type by value? I think yes. The question is does cdr> return by value also copy all the value_type's? I'm guessing not because cdr> this would be a huge performance hit. Just the property map itself is cdr> copied. Correct? The copy semantics for property maps is required to be shallow, so that copying is lightweight. In browsing through the online property map docs it looks like I forgot to make that explicit. cdr> 2. In the case of my algorithm visitor, I am passed a const reference cdr> to a graph that will result in a boost::get returning a const_type a cdr> property map. I can understand that changing the value_type's of an cdr> arbitrary property map could potentially screw up an algorithm (if cdr> the algorithm is using the specific property that I am trying to cdr> write). Is this why the graph passed to the visitor is const? In the cdr> case where I need to write an internal property map that is not being cdr> used by the specific algorithm (in the case of my dfs search, dfs is cdr> using the vertex color and I want to write another, distinct internal cdr> property map that I have registered with my graph class), I should cdr> pass a reference to the specific map into the constructor of the cdr> visitor? Yes, that would work. cdr> Thank you for your help Jeremy. You bet! Cheers, Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
participants (2)
-
Chris Russell
-
Jeremy Siek