1

I am pretty new to Boost Graphs and perhaps there is a solution to my problem.

I have a function that performs certain computation on a graph. It expects graphs with a particular properties, e.g. it expects that all edges will have a numerical weight value and all vertices will have a numerical field (lets call it a color, it will be preset to some meaningful value prior to call to my function).

Imagine that I have a set of different graph types, all of them have numeric weight property on a link and all their vertices have a numeric color, however they also have other properties for vertices and edges. My question is how can I use my function for all of these graph types?

  1. Naturally to me it seems like an inheritance, if boost graphs would be classes then my function could operate on a base classes, and I could pass in pointer to a child classes etc.
  2. Initially I've been trying to declare my function to take in a template graph argument, but soon I realized that it doesn't work (or I couldn't figure out how to do it properly).

Thanks!

kirbo
  • 1,707
  • 5
  • 26
  • 32
  • 2
    That's exactly what property map's were invented for in BGL, I recommend spending more time on the doc (it can be quite confusing). (option 2 btw) – Marc Glisse Feb 28 '15 at 17:52

1 Answers1

1

The "technique equivalent to inheritance" is called "polymorphism" and BGL favours "static polymorphism" (option 2!).

This is the pay-for-what-you-need approach to generic libraries.

You can adapt any type (hierarchy) for use with BGL's static polymorphism though:

Also use property maps to link the properties (weight, color) to the vertices/edges.

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633