Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Default-constructibility of vertices
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-12-13 00:04:14


On Mon, 12 Dec 2011, Kelvin Chung wrote:

> Suppose I have a class hierarchy, like so:
>
> struct Foo {
> virtual Output doSomething(const Input& in);
> };
>
> class CompositeFoo {
> std::vector<Foo*> fooList; // Use your favorite smart pointer
> standin for Foo* here
> public:
> Output doSomething(const Input& in);
> };
>
> Now, suppose I have a functor:
>
> class Functor {
> Foo* foo;
> Input input; // assume Input is copyable
> public:
> Output operator()() { foo->doSomething(input); }
> };
>
> Now, the structure of doSomething() calls leads to a DAG structure with
> Functor as the vertices. What I want to do is create a graph with BGL that
> shows that structure, before topologically sorting it and doing other stuff
> with it. However, it would appear that the vertices of the graph (which I
> would assume to be of type boost::adjacency_list<boost::vecS, boost::vecS,
> boost::directedS, Functor>) must be default-constructible, which Functor is
> clearly not. Is there a nice workaround to this without changing the vertex
> type to Functor* (again, use your favorite smart pointer standin for Functor*
> here)?

Have you tried using the two-parameter version of add_vertex() (with
vertex property value as the first parameter)? I don't know if that would
work, but it might. The requirements for property types (at least for
old-style properties) say that they need to be default constructible,
though, so you might need to use a pointer. Is the assumption on Input in
your example that it isn't default constructible? Otherwise, Functor
should be as well.

-- 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