jeudi 6 février 2020

How to dynamically add template parameter

I'm new to C++ and have got stuck with an implementation. So my problem is as below:

I have interface classes, where the only difference in the classes is the no. of parameters one of its function has.

For Example:

class foo3()
{
    private:
       function3(a,b,c) {}
};

class foo5()
{
    private:
       function5(a,b,c,d,e) {}
};

To generalize these and use them without knowing their inner functionality, I have created a template class fooN and used template specialization, thus based on template parameter(int N) I can choose correct class object and do some processing.

Now I have algorithm where I'm creating an object of fooN template

class algo {
     public:
         fooN<5> fooObj;
     private:
 }

Is it possible to dynamically assign this template parameter(5) at run-time, or is there a work-around?

Currently I'm using CMake to statically set the template parameter.

Aucun commentaire:

Enregistrer un commentaire