This needs a different approach

Saaa empty at needmail.com
Mon Apr 28 08:27:40 PDT 2008


I have this piece of code:

enum { APPLE, PEAR .. PLUM}

switch (data.type)
  {
   case APPLE:
   groupModule.appleModule.eat();
    break;
   case PEAR:
   groupModule.pearModule.eat();
    break;
..
..
   case PLUM:
   groupModule.plumModule.eat();
    break;
   default:
    break;
  }

As the function is always the same I'd rather see a lookup iso an iteration 
over all options.. but how?

groupModule.(data.type).eat();

Something like this is both faster and a lot less to code :) 




More information about the Digitalmars-d-learn mailing list