Calling the appropriate function based on an enumeration, but using templates

Viewed 1015

I have this wrapper function that is supposed to call the appropriate function on a large dataset based on the type of data it contains, like this:

void WrapperFunc( int iRealDataType, int iUseAsDataType )
{
    // now call the right function based on both arguments
    switch ( iRealDataType )
    {
          case FancyType1:
          switch ( iUseAsDataType )
          {
               case CoolType1: DataAnalysisFunc_Fancy1_Cool1(); break;
               // etc.
          }
          // etc.
    }
}

So far, this was solved by having two nested switch statements and then calling one of the many many specialized functions for each existing combination of Real and UseAs data type. However as the number of defined types grows it is a nightmare to maintan the code base. So I decided to finally use templates. I mostly avoid them if I can, but this time they suit the problem well.

So now instead of DataAnalysisFunc_Fancy1_Cool1 i would like to call DataAnalysisFunc<FancyType1,CoolType1> ang get rid of the hundreds of lines of switch statements, BUT i cannot use it like this, since FancyType1 is an enum, not the type (which is Fancy1 for example).

Just to clarify - I know this sounds like a stupid artificial example, but I tried to simplify the problem as much as possible to get to the core of it, instead of explaining the ton of details that would go into a much more concrete example.

EDIT: my data analysis functions are in reality CUDA kernels - this will probably rule out some possible solutions. Sorry for that.

3 Answers
Related