In my design, I have a class (let it be Shell
) that is templated against a large number of parameters. Most of those parameters are other classes that I define within my project, since I have chosen a Policy-Based-Design approach for my project.
The class declaration looks something like this:
template <class int_t, class float_t, class Pol1, class Pol2,..., class PolN>
class Shell : Pol1, Pol2,...,PolN
The two first arguments are the integer and floating types that shall be used. The remaining paramenters are specific policies definied within the project.
This type of design is convenient for me, since it allows to avoid a lot of run-time checks (and we are targeting run-time performance). However, it is very messy (from a user perspective) to type a list of 10+ arguments whenever he/she wants to create an instance of the Shell
class.
For this reason, I have chosen to move this typing burden to a separate file, along with macros. First, I default all the policies to a macro:
template <class int_t, class float_t, class Pol1 = DEF_1, class Pol2 = DEF_2,..., class PolN = DEF_N>
class Shell : Pol1, Pol2,...,PolN
And the template parameters can be provided in a separate files, as macros, instead of in the declaration of the solver. For example:
#include <shell.cpp>
#define DEF_1 example1
#define DEF_2 example2
...
#define DEF_N exampleN
int main(){
Shell<int,double> MyShell();
return 0;
}
This way, instantiating the class only needs passing to template parameters (the other +10 parameters are passed via the macros). The define's could be even moved to a separate file, as in:
#include <shell.cpp>
#include "define.hpp"
This is just a workaround, so that one does not have to provide a 10+ parameters argument list everytime you create an instance of the class. Macros are the best solution I have found so far. However, I know that macros are not a "recommended" solution in most C++ applications.
For this reason, I would like to know if this is a typical problem, and how can you overcome it without macros. I would also like to know if macros are an "ok" solution, or if I should avoid this design at all cost. I would appreciate any help/comment on this topic, since I am quite new to C++ :)