Boost logo

Boost Users :

Subject: Re: [Boost-users] property type trait
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2012-01-02 10:35:03

On Sat, 31 Dec 2011, Amir Yazdanbakhsh wrote:

> Hi,

> I new to boost graph library. The thing that I have in my mind is to
> find the type of property that passed to a function and execute
> something based on that. I implemented two bundled properties each for
> vertex and edge. I want to implement a general function, say print a
> property, if the passed property is a vertex property the function
> should iterate over vertices and print out them and if it's edge
> property it should iterate over edges. Is it any way to do that? Thanks

Whether a bundled property belongs to vertices or edges is a property of
the graph, not of the property class. The easiest way to do what you want
is to have a traits class (metafunction) that you define for your property
classes and then dispatch on that. Here's what I have in mind:

struct is_vertex_property {};
struct is_edge_property {};

struct my_vertex_prop {
   // Members
   typedef is_vertex_property category;

struct my_edge_prop {
   // Members
   typedef is_edge_property category;

template <typename Prop>
void foo_dispatch(const Prop& prop, is_vertex_property) { ... }

template <typename Prop>
void foo_dispatch(const Prop& prop, is_edge_property) { ... }

template <typename Prop>
void foo(const Prop& prop) {
   foo_dispatch(prop, typename Prop::category());

-- Jeremiah Willcock

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at