Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Bundled properties and property maps
From: Andrew Sutton (andrew.n.sutton_at_[hidden])
Date: 2009-01-15 08:35:31


>
> const property_map<...>::const_type map; // or something similar.
>>
>> For all property maps, map = get(...) is a valid expression,
>> regardless of whether your map is a ::type or ::const_type. By
>> declaring it const, and then instantiating a template with the const
>> pmap, you're going to run into problems - probably the problem you
>> reported earlier.
>>
>

>
>> Okay, so if I understand correctly I shouldn't use const prop maps with
> const_type at all?
>
> It seems to me like a line such as the above should still theoretically
> compile. At least from the perspective of a concept check for Readability;
> this is by definition what const is meant to restrict objects to so in
> theory in should be allowable no? If I'm right it would be a compilation
> error caused by the underlying implementation. Either that or a debatable
> foible that should be documented? *shrug*.

I don't think you should be using const property maps at all - with type or
const_type. For example:

/* 1 */ property_map<...>::const_type p; // Good
/* 2 */ const property_map<...>::const_type p; // Bad

The const_type in 1 forces the p to operate on its underlying reference in a
const way. Returing const references, no put() operation, etc. The leading
const in 2 means that you can't write:

p = q; // Assuming q is type property_map<...>::type

It's a compiler error since p is not modifiable.

If you look at the concept definition in boost/property_map.hpp for
ReadablePropertyMapConcept, you'll find, in the constraints() member, this
line:

val = get(pmap, k)

So apparently, the concept definition actually requires that property maps
are never const - which is admittedly a little weird.

Andrew Sutton
andrew.n.sutton_at_[hidden]



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net