I have the following class hierarchy (actually there are a whole lot more classes), I was wondering if its possible to reorganize the following to make use of static polymorphism?
struct return_val {};
struct base
{
virtual ~base(){}
virtual return_val work(){};
};
struct derivedtype1 : public base
{
return_val work() { return localwork(next_type.work()); }
return_val localwork(return_val& rv0){....}
base* next_type0;
};
struct derivedtype2 : public base
{
return_val work() { return localwork(next_type0.work(),next_type1.work()); }
return_val localwork(return_val& rv0, return_val& rv1){....}
base* next_type0;
base* next_type1;
};
struct derivedtype3 : public base
{
return_val work() { return localwork(next_type0.work(),next_type1.work(),next_type2.work()); }
return_val localwork(return_val& rv0, return_val& rv1, return_val& rv2){.....}
base* next_type0;
base* next_type1;
base* next_type2;
};
I ask as after having done a great deal of profiling, the overhead from virtual method calls is actually quite large and was hoping to optimize it away as much as possible.