Boost Graph: why can't get() take a const argument?

Hi, I have a question about line 54 of the canonical_ordering example: graph g(6); ... property_map<graph, edge_index_t>::type e_index = get(edge_index, g); If I'm reading the Boost source code correctly, the get function's graph argument is declared const. This makes sense intuitively because, well, why would the graph need to be modified in order to retrieve a property? So the graph parameter passed to get() could be made const, correct? Like this: graph g(6); ... const graph g2 = g; property_map<graph, edge_index_t>::type e_index = get(edge_index, g2); However, the above change gives a compiler error: conversion from ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, const int&, size_t, const boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ to non-scalar type ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, int&, size_t, boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ requested Can anyone explain why? Thank you, Trevor

On 03/05/2010 7:33 PM, Trevor Harmon wrote:
Hi,
I have a question about line 54 of the canonical_ordering example:
graph g(6); ... property_map<graph, edge_index_t>::type e_index = get(edge_index, g);
If I'm reading the Boost source code correctly, the get function's graph argument is declared const. This makes sense intuitively because, well, why would the graph need to be modified in order to retrieve a property? So the graph parameter passed to get() could be made const, correct? Like this:
graph g(6); ... const graph g2 = g; property_map<graph, edge_index_t>::type e_index = get(edge_index, g2);
However, the above change gives a compiler error:
conversion from ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, const int&, size_t, const boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ to non-scalar type ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, int&, size_t, boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ requested
Can anyone explain why? Thank you,
Trevor
I've run into this myself (and asked about it in this list somewhere as well), the short answer is that it's easier to simply pass in a non-const graph. I can't remember the long answer, but I believe it has to do with the implementation of property_map<..>::type and const_type and the property (eg. edge_index_t) template parameter. Note though that I could (and may well) be wrong. Geoff

On 04/05/2010 10:38 AM, Geoff Hilton wrote:
On 03/05/2010 7:33 PM, Trevor Harmon wrote:
Hi,
I have a question about line 54 of the canonical_ordering example:
graph g(6); ... property_map<graph, edge_index_t>::type e_index = get(edge_index, g);
If I'm reading the Boost source code correctly, the get function's graph argument is declared const. This makes sense intuitively because, well, why would the graph need to be modified in order to retrieve a property? So the graph parameter passed to get() could be made const, correct? Like this:
graph g(6); ... const graph g2 = g; property_map<graph, edge_index_t>::type e_index = get(edge_index, g2);
However, the above change gives a compiler error:
conversion from ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, const int&, size_t, const boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ to non-scalar type ‘boost::adj_list_edge_property_map<boost::undirected_tag, int, int&, size_t, boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>’ requested
Can anyone explain why? Thank you,
Trevor
I've run into this myself (and asked about it in this list somewhere as well), the short answer is that it's easier to simply pass in a non-const graph. I can't remember the long answer, but I believe it has to do with the implementation of property_map<..>::type and const_type and the property (eg. edge_index_t) template parameter. Note though that I could (and may well) be wrong.
Geoff
I've double-checked and found the thread I was thinking of, search for messages containing the subject "[BGL] Bundled properties and property maps" that'll get you the thread, as well as "[BGL] A bug in const bundle_property_map or in Readable Property Map Concept?" though according to Andrew the issue in question was fixed in 1.40, so you might have found something new unless you're using a prior incarnation.

On May 4, 2010, at 7:57 AM, Geoff Hilton wrote:
I've double-checked and found the thread I was thinking of, search for messages containing the subject "[BGL] Bundled properties and property maps" that'll get you the thread,
http://lists.boost.org/boost-users/2008/12/43247.php
as well as "[BGL] A bug in const bundle_property_map or in Readable Property Map Concept?"
http://lists.boost.org/boost-users/2009/05/48237.php
though according to Andrew the issue in question was fixed in 1.40, so you might have found something new unless you're using a prior incarnation.
I'm using Boost 1.42.0. I filed a bug on this: https://svn.boost.org/trac/boost/ticket/4188 Trevor

On 04/05/2010 2:43 PM, Trevor Harmon wrote:
On May 4, 2010, at 7:57 AM, Geoff Hilton wrote:
I've double-checked and found the thread I was thinking of, search for messages containing the subject "[BGL] Bundled properties and property maps" that'll get you the thread,
http://lists.boost.org/boost-users/2008/12/43247.php
as well as "[BGL] A bug in const bundle_property_map or in Readable Property Map Concept?"
http://lists.boost.org/boost-users/2009/05/48237.php
though according to Andrew the issue in question was fixed in 1.40, so you might have found something new unless you're using a prior incarnation.
I'm using Boost 1.42.0. I filed a bug on this:
https://svn.boost.org/trac/boost/ticket/4188
Trevor
Great!

On Wed, 5 May 2010, Geoff Hilton wrote:
On 04/05/2010 2:43 PM, Trevor Harmon wrote:
On May 4, 2010, at 7:57 AM, Geoff Hilton wrote:
I've double-checked and found the thread I was thinking of, search for messages containing the subject "[BGL] Bundled properties and property maps" that'll get you the thread,
http://lists.boost.org/boost-users/2008/12/43247.php
as well as "[BGL] A bug in const bundle_property_map or in Readable Property Map Concept?"
http://lists.boost.org/boost-users/2009/05/48237.php
though according to Andrew the issue in question was fixed in 1.40, so you might have found something new unless you're using a prior incarnation.
I'm using Boost 1.42.0. I filed a bug on this:
Is using property_map<graph>::const_type not acceptable? That does work right now. -- Jeremiah Willcock

On 05/05/2010 2:52 PM, Jeremiah Willcock wrote:
On Wed, 5 May 2010, Geoff Hilton wrote:
On 04/05/2010 2:43 PM, Trevor Harmon wrote:
On May 4, 2010, at 7:57 AM, Geoff Hilton wrote:
I've double-checked and found the thread I was thinking of, search for messages containing the subject "[BGL] Bundled properties and property maps" that'll get you the thread,
http://lists.boost.org/boost-users/2008/12/43247.php
as well as "[BGL] A bug in const bundle_property_map or in Readable Property Map Concept?"
http://lists.boost.org/boost-users/2009/05/48237.php
though according to Andrew the issue in question was fixed in 1.40, so you might have found something new unless you're using a prior incarnation.
I'm using Boost 1.42.0. I filed a bug on this:
Is using property_map<graph>::const_type not acceptable? That does work right now.
-- Jeremiah Willcock
const_type! Good point, I hadn't thought of it. I'm thinking it may be a case of under-documentation. I believe I was originally told that const_type is primarily an implementation detail, whether I'm remembering incorrectly or that has changed, it might be a good idea to mention const_type and its' purpose in the documentation, along with (at least) a one or two line example for the sake of making things mind-numbingly clear. Hopefully, the (seemingly) oft-raised question can then finally be put out to pasture. Geoff

On May 5, 2010, at 11:52 AM, Jeremiah Willcock wrote:
Is using property_map<graph>::const_type not acceptable? That does work right now.
I can't seem to get const_type to work. If I understand its usage correctly, I can pass a const graph to get() like this (from canonical_ordering.cpp): const graph g2 = g; property_map<graph, edge_index_t>::const_type e_index = get(edge_index, g2); But that just gives me a different kind of compiler error: /Users/twharmon/Development/boost_1_42_0/boost/property_map/ property_map.hpp: In function ‘void boost::put(const boost::put_get_helper<Reference, PropertyMap>&, K, const V&) [with PropertyMap = boost::adj_list_edge_property_map<boost::undirected_tag, int, const int&, size_t, const boost::property<boost::edge_index_t, int, boost::no_property>, boost::edge_index_t>, Reference = const int&, K = boost::detail::edge_desc_impl<boost::undirected_tag, size_t>, V = size_t]’: canonical_ordering.cpp:60: instantiated from here /Users/twharmon/Development/boost_1_42_0/boost/property_map/ property_map.hpp:325: error: assignment of read-only location Am I using const_type incorrectly? Thanks, Trevor
participants (3)
-
Geoff Hilton
-
Jeremiah Willcock
-
Trevor Harmon