Since the function template in the following code is a member of a class template, it can't be specialized without specializing the enclosing class.
But if the compiler's full optimizations are on (assume Visual Studio 2010), will the if-else-statement in the following code get optimized out? And if it does, wouldn't it mean that for all practical purposes this IS a function template specialization without any performance cost?
template<typename T>
struct Holder
{
T data;
template<int Number>
void saveReciprocalOf();
};
template<typename T>
template<int Number>
void Holder<T>::saveReciprocalOf()
{
//Will this if-else-statement get completely optimized out
if(Number == 0) data = (T)0;
else data = (T)1 / Number;
}
//-----------------------------------
void main()
{
Holder<float> holder;
holder.saveReciprocalOf<2>();
cout << holder.data << endl;
}