Boost logo

Boost Users :

Subject: Re: [Boost-users] Extend boost::adjacency_list
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-10-03 17:28:27


On Mon, 3 Oct 2011, Jupp Tscheak wrote:

> Dear users of boost graph library,
> I would like to extend boost::adjacency_list like this
>
> code:
> class MyGraph:
>     public boost::adjacency_list<boost::multisetS,
>                                  boost::vecS,
>                                  boost::bidirectionalS,
>                                  boost::property<boost::some_vertex_property, SomeVertexProperty*>,
>                                  boost::property<boost::some_edge_property, SomeEdgeProperty*> {}
>
> This works as expected.
>
> Is it possible to extend class "MyGraph" with additional vertex and/or edge properties defined?
>
> My first approach was like this
>
> code:
> template <class AdditionalVertexProperty = boost::no_property, class AdditionalEdgeProperty = boost::no_property>
> class MyGraph:
>     public boost::adjacency_list<boost::multisetS,
>                                  boost::vecS,
>                                  boost::bidirectionalS,
>                                  boost::property<boost::some_vertex_property, SomeVertexProperty*, AdditionalVertexProperty>,
>                                  boost::property<boost::some_edge_property, SomeEdgeProperty*, AdditionalEdgeProperty> {}
>
> class ExtendedMyGraph: public MyGraph<boost::property<boost::some_add_vertex_property, SomeAddVertexProperty*> > {}
>
>
> This, however, led into multiple compiler errors. Does anyone know how to achieve the wanted behavior?

It is unsafe to subclass BGL graph types. However, you can define a
metafunction that does what you want:

template <typename VP = boost::no_property, typename EP = boost::no_property>
struct gen_MyGraph {
   typedef <your big adjacency_list type> type;
};

and then use gen_MyGraph<boost::property<...> >::type as your graph type.

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