I wish to modify an existing templated class. The class's template arguments are (semi) variable and I would like to use them to generate a conditional/switch/map like function body.
My compiler does not support variadic templates so the (boost) preprocessor is currently used to generate the existing class:
template <typename item0, typename item1, typename item2 ..., typename itemN>
struct myclass { /*various operations*/ };
A new function func is required that will query variables at run-time and return an object of a that is one of the template arguments.
Example:
template <typename item0, typename item1, typename item2 ...>
struct my_class {
//...various operations
//automatic generatation possible?
std::string * func()
{
string s;
while(data) {
switch (data[0])
{
case item0::id:
s += item0::get_name();
case item1::id:
s += item1::get_name();
//... for each template arguemnt typename where typename is no void
}
}
return s;
}
};
typedef my_class<a, b, c> class_one;
typedef my_class<d, e, f> class_two;
typedef my_class<a, b, c, x, y, z> class_three;
int main()
{
...
class_one test;
test.func();
...
}
I would like to generate the contents of func() because the number of items will be numerous, and the number of types of "myclass" will be even higher.
Can someone give me an idea of how any techniques that could accomplished this?
I already have a dependency on boost. My compiler is reasonably new (but does not support variadic templates). I would prefer not to take any new dependencies or introduce more complexity than necesssary.