[Lemon-user] Generic algorithm that can take different SubDigraph types as input?

Gabriel Gouvine gabriel.gouvine at gmx.com
Mon Mar 6 23:02:40 CET 2017


Hi David,

In this particular case, you want to use a generic graph type (GR
below), and use it as the type inside your function, so you want
something like:

template<typename GR>
void func(const GR &sub) {
	for (GR::NodeIt v(sub); v != lemon::INVALID; ++v) {
		...
	}
}

But it wouldn't compile as is. Since it's a dependent type, you need to
add the "typename" keyword:

template<typename GR>
void func(const GR &sub) {
	for (typename GR::NodeIt v(sub); v != lemon::INVALID; ++v) {
		...
	}
}

Hope this helps,
Gabriel


Le 06/03/2017 à 18:27, David Franz Koza a écrit :
> Dear all,
> 
> I coded a graph algorithm, which I would like to call for differently specified SubDigraphs as input (or even other types of Digraphs). Without having to duplicate the code, how can I code my algorithm in a generic way?
> 
> In my particular case I have different SubDigraphs, e.g.:
> lemon::SubDigraph< lemon::SmartDigraph, lemon::SmartDigraph::NodeMap<bool>, lemon::SmartDigraph::ArcMap<bool> > sub1;
> or
> lemon::SubDigraph< lemon::SmartDigraph, lemon::CombineMap< lemon::SmartDigraph::NodeMap<bool>, lemon::SmartDigraph::NodeMap<bool>, std::logical_and<bool> >, lemon::SmartDigraph::ArcMap<bool> > sub2;
> 
> i.e. the first one is defined over a standard NodeMap<bool>, while the second one is defined over a CombineMap of two NodeMap<bool>. When looping through vertices in the algorithm, however, the SubDigraph type needs to be specified explicitly. How can I make the following code work for both SubDigraph (or, more generally, other Digraph) specifications:
> 
> for (lemon::SubDigraph< lemon::SmartDigraph, lemon::SmartDigraph::NodeMap<bool>, lemon::SmartDigraph::ArcMap<bool> >
> ::NodeIt v(sub1); v != lemon::INVALID; ++v) {
> ...
> }
> 
> Question http://lemon.cs.elte.hu/pipermail/lemon-user/2011-October/000483.html is similar and suggests to use template functions. Could you provide a tiny example of how a solution using template functions would look like in the above case?
> 
> Thanks,
> David
> 
> 
> 
> _______________________________________________
> Lemon-user mailing list
> Lemon-user at lemon.cs.elte.hu
> http://lemon.cs.elte.hu/mailman/listinfo/lemon-user
> 



More information about the Lemon-user mailing list