[property_map] bit vector as property map

Hello everybody! I'm using the property_map scheme to pass some data-structures to vistors of BGL-algorithms. So far I usually use a vector in the manner: std::vectorstd::size_t props(num_vertices(my_graph), 0) Then I do something like bfs_search(..., make_my_vistor(&props[0]), ...) which works ok and passes me a correct property_map into the visitor created by make_my_visitor. Within that visitor I can then do the usual stuff like put(the_props_map, vertex_id, someValue) At least that's how I understood, how the property_map concept works. However, if I use a bit-vector the above scheme breaks down to work: std::vector<bool> bit_props(num_vertices(my_graph), false) bfs_search(..., make_my_vistor(&bit_props[0]), ...) The compiler compiles these lines, but complains that a temprorary is passed as a reference to make_my_visitor and the code generated crashes. My system is a Ubununtu Edgy with boost 1.33.1 and g++ 4.1.2. Any ideas why this happens and what I can do here? Thanks a lot in advance. Greetings, Sebastian

On Feb 9, 2007, at 2:38 AM, Sebastian Weber wrote:
At least that's how I understood, how the property_map concept works. However, if I use a bit-vector the above scheme breaks down to work:
std::vector<bool> bit_props(num_vertices(my_graph), false)
bfs_search(..., make_my_vistor(&bit_props[0]), ...)
The compiler compiles these lines, but complains that a temprorary is passed as a reference to make_my_visitor and the code generated crashes. My system is a Ubununtu Edgy with boost 1.33.1 and g++ 4.1.2. Any ideas why this happens and what I can do here?
The problem here is that vector<bool> does a space "optimization" by packing bool values into individual bits, and you can't take the address of a bit. Instead of trying to get a pointer to the bits, use iterators into the bit vector, e.g., bfs_search(..., make_my_vistor(bit_props.begin()), ...) Cheers, Doug

Hi Doug,
The problem here is that vector<bool> does a space "optimization" by packing bool values into individual bits, and you can't take the address of a bit. Instead of trying to get a pointer to the bits, use iterators into the bit vector, e.g.,
bfs_search(..., make_my_vistor(bit_props.begin()), ...)
I already thought that this might cure the problem, but it did not. I do not remember the error message, since I use a different ansatz by now. However, the program crashed with the .begin()-directive (maybe my program was faulty, but I don't know). Nevertheless, thanks a lot for your help. Anyway, even it is off-topic, I'm wondering weather a put(someMap, key, get(someMap, key) + 1) is much slower than doing it directly (I know that map is a vector and key is a std::size_t-index) via ++someMap[key]; Or is the compiler so smart to make the first expression equal to the last one? Since I'm doing lots of stuff like this (and I don't care to much about generality, but rather raw performance), this would be very important to know. For sure I will try it out, but I'm anyway interested in your opinion, concering that point. Greetings, Sebastian
Cheers, Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Feb 9, 2007, at 10:52 AM, Sebastian Weber wrote:
Anyway, even it is off-topic, I'm wondering weather a
put(someMap, key, get(someMap, key) + 1)
is much slower than doing it directly (I know that map is a vector and key is a std::size_t-index) via
++someMap[key];
Or is the compiler so smart to make the first expression equal to the last one? Since I'm doing lots of stuff like this (and I don't care to much about generality, but rather raw performance), this would be very important to know. For sure I will try it out, but I'm anyway interested in your opinion, concering that point.
Without measuring it, I can't tell you for certain. With a decent inliner, there should be no difference in the performance. Cheers, Doug

Or is the compiler so smart to make the first expression equal to the last one? Since I'm doing lots of stuff like this (and I don't care to much about generality, but rather raw performance), this would be very important to know. For sure I will try it out, but I'm anyway interested in your opinion, concering that point.
Without measuring it, I can't tell you for certain. With a decent inliner, there should be no difference in the performance.
I tried it and there has been no differences in performance! Greetings, Sebastian
Cheers, Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Doug Gregor
-
Douglas Gregor
-
Sebastian Weber