Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] possible Bug in property handling
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2009-08-28 13:24:35


On Fri, 28 Aug 2009, Ralf Goertz wrote:

> Hi,
>
> I'm new to BGL (and generic programming) so this may well not be a bug
> but I don't know how this could be intended. Consider the following
> program:
>
>
> #include <string>
> #include <iostream>
> #include <boost/graph/graph_traits.hpp>
> #include <boost/graph/properties.hpp>
> #include <boost/graph/adjacency_list.hpp>
>
> using namespace boost;
>
>
> typedef property<vertex_name_t, std::string> VertexProp;
> //this crashes
> typedef adjacency_list < vecS, vecS, undirectedS,VertexProp, no_property > graph_t;
> //this doesn't
> //typedef adjacency_list < vecS, listS, undirectedS,VertexProp, no_property > graph_t;
> typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
> typedef property_map<graph_t, vertex_name_t>::type id_name_map_t;
> typedef graph_traits<graph_t>::vertex_iterator vi_t;
> std::pair<vi_t,vi_t> vi;
>
>
> int main(){
> graph_t g;
> vertex_descriptor vd;
> id_name_map_t name_map;
> vd=add_vertex(g);
> put(name_map,vd,"foo");
> for (vi=vertices(g); vi.first!=vi.second;++vi.first) {
> std::cout<<get(name_map,*vi.first)<<std::endl;
> }
> return EXIT_SUCCESS;
> }

It appears that name_map is not initialized. You need to do something
like:

id_name_map_t name_map = get(vertex_name, g);

to get the property map before you use it.

-- Jeremiah Willcock


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