Use of templates to avoid redudancy of code

Mael mael.primet at gmail.com
Tue Jun 3 02:39:24 PDT 2008


Hello,

I'm writing an algorithm that has, say, too possible behaviour depending on a switch. Since there are many imbricated loops, and the behaviour change is inside the loop, testing for the flag is time-consuming

for( ....)
for( .... )
for( ... )
{
  if( flag ) action_1 ;
  else action_2 ;
}

is there a clean way to use templates to generate the duplicate of the code like

if( flag )
{
  for(...) .... action1 ;
}
else
{
  for(...) .... action2 ;
}




More information about the Digitalmars-d-learn mailing list