property type trait
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 Best Regards, A. Yazdanbakhsh
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PhD. Student School of Electrical and Computer Engineering University of Wisconsin-Madison E-mail: yazdanbakhsh@wisc.edu <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
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
participants (2)
-
Amir Yazdanbakhsh
-
Jeremiah Willcock