Hi,
I've been trying to understand templates and metaprogramming for a while, but while I understand and write a few normal template classes I never got around to grasping the basics of metaprogramming.
In any case, I believe I have a case where it could be applied, but I'm not sure. Here goes.
I have a function that gets calles thousands of time. The function is mainly like this:
the flag is defined at run-time, not design time.
Still, I believe I could get rid of the switch with a function template or some clever use of templates. This function gets called so much that any optimization would be welcome, even if it's not a bottleneck.
I've read some books on templates, but while I understand what I'm reading, I find that I'm rarely able to put it in practive.
So, is this a case where templates could help?
Thanks,
--Eric
I've been trying to understand templates and metaprogramming for a while, but while I understand and write a few normal template classes I never got around to grasping the basics of metaprogramming.
In any case, I believe I have a case where it could be applied, but I'm not sure. Here goes.
I have a function that gets calles thousands of time. The function is mainly like this:
- Code:
void Function(flag)
{
switch(flag)
{
case _this_:
do this;
break;
case _that_:
do that;
break;
}
}
the flag is defined at run-time, not design time.
Still, I believe I could get rid of the switch with a function template or some clever use of templates. This function gets called so much that any optimization would be welcome, even if it's not a bottleneck.
I've read some books on templates, but while I understand what I'm reading, I find that I'm rarely able to put it in practive.
So, is this a case where templates could help?
Thanks,
--Eric