TIA.
-regards,
Larry
-[---- cut here ----
unsigned value=0;
#define MAX_INDEX 3
template
< unsigned Index
>
unsigned fun(void)
{
value+=Index+1;
return value;
}
typedef unsigned(*fun_type)(void);
#ifdef CONSTEXPR_ENABLED
constexpr
#else
const
#endif
fun_type
fun_vec[MAX_INDEX]=
{ fun<0>
, fun<1>
, fun<2>
};
int dispatch_funvec(unsigned index)
{
return fun_vec[index]();
}
int dispatch_switch(unsigned index)
{
switch (index)
{
case 0:
return fun<0>();
case 1:
return fun<1>();
case 2:
return fun<2>();
default:
return -1;
}
}
-]---- cut here ----
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Basically, yes. dispatch_funvec is very much harder to optimise than
dispatch_switch, because indirect function calls (through a function
pointer) are very hard to expand inline. With functions as small (and
similar) as in your example, that could make a noticeable difference.
Bart v Ingen schenau