Boost Graph: vertex class has no copy constructor

Hi,
I'm using the Boost Graph library to construct a directed graph:
typedef boost::directed_graph<BasicBlock> Graph;
The vertex class, "BasicBlock", is not my own; it comes from the LLVM
project.
Unfortunately, the declaration above causes a slew of compiler errors
(see below) that appear to be related to BasicBlock's copy
constructor. Sure enough, I checked BasicBlock.h, and its copy
constructor is declared private and is not even implemented. There
appears to be some sort of design issue that prevents this class from
having a copy constructor.
Is there some workaround for this on the Boost Graph side, or must
vertex classes always have a copy constructor?
Thanks,
Trevor
/Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp:
In constructor ‘boost::property

Hi Trevor, Unfortunately, the declaration above causes a slew of compiler errors (see
below) that appear to be related to BasicBlock's copy constructor. Sure enough, I checked BasicBlock.h, and its copy constructor is declared private and is not even implemented. There appears to be some sort of design issue that prevents this class from having a copy constructor.
Is there some workaround for this on the Boost Graph side, or must vertex classes always have a copy constructor?
The "easy" workaround is to simply have the graph refer to BasicBlock by
pointer instead of actually owning it. Pointers are definitely default and
copy constructible :) Otherwise, those property classes are largely required
to be copy and/or default constructible.
I might caution you about using directed_graph. It's built over
adjacency_list

On Mar 26, 2010, at 5:42 AM, Andrew Sutton wrote:
The "easy" workaround is to simply have the graph refer to BasicBlock by pointer instead of actually owning it. Pointers are definitely default and copy constructible :)
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
I might caution you about using directed_graph. It's built over adjacency_list
so it might not be usable quite the same way that most of the documentation is listed.
So instead of:
typedef directed_graph

The "easy" workaround is to simply have the graph refer to BasicBlock by
pointer instead of actually owning it. Pointers are definitely default and copy constructible :)
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
It's not surprising that graph[0] crashes for directed_graph; it's vertex descriptors are actually list iterators. It turns out that 0 is an implicit constructor for directed_graph<...>::null_vertex(). The (current BGL) documentation doesn't spell this out very well, and almost none of the examples demonstrate this fact. I think you could use: graph[vertex(g, 0)] but that might be O(n). I should do maybe:
typedef adjacency_list
TimingGraph;
If you're not going to remove vertices, then that's probably a good bet. I forget if this is good for removing edges also. I'm guessing "no". Andrew Sutton andrew.n.sutton@gmail.com

On Mar 26, 2010, at 11:36 AM, Trevor Harmon wrote:
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
Never mind the above; I was doing something dumb. One of the graphs I had created was empty, and so graph[0] was being called on an empty graph. Still, I'm not sure why that would actually cause a segfault. In fact, it wasn't the call that was causing the segfault but rather the assignment: graph[0]; // okay void foo* = graph[0]; // bus error Anyway, at least it's working now... Trevor
participants (3)
-
Andrew Sutton
-
Trevor Harmon
-
Trevor Harmon