Since pointers to template functions are not possible in C++ I would like to know how to go about solving the following issue:
Given the template function:
To use this function you obviously do:
template <typename T> static T LinearInterpolate(T value1, T value2, float lerpFactor)
return static_cast<T>(value1 + lerpFactor * (value2 - value1));
However this will be littered throughout my code. If I want to change the type of linear interpolation (IE: cosine interpolation) using this approach I will have to go through the code and change all LinearInterpolate calls to some other template function. However it is nice to have a template function here b/c you can then LinearInterpolate between any type that has the correct operators overloaded which is quite handy.
float floatResult = Math.Utils.LinearInterpolate<float>(10.0f,20.0f,0.5f);
double doubleResult = Math.Utils.LinearInterpolate<double>(10.0,20.0,5.0f);
D3DXCOLOR colorResult = Math.Utils.LinearInterpolate<D3DXCOLOR>(D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f), D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), 0.5f);
It would be nice to simply use a function pointer to Math.Utils.LinearInterpolate which then would mean to alter the function being used I would simply alter what function the pointer pointed to...but b/c it is a template this is not an option.
EDIT: Fixed typo in code that used coef instead of lerpFactor.