Let say that I have a function more or less like this (pseudo code, not a real one so please do not consider how much it is useless :P ):
template <typename T>
T function()
{
std::vector<size_t> a = {1, 2, 3, 4, 5};
T r = 0;
for (size_t i=0; i<a.size(); ++i)
{
r += static_cast<T>(a[i]);
}
return r;
}
Now i'd like to know if compiler will optimize out static_cast if T=size_t. I know that there is not much todo if T will be an int but will it be optimized out or solved on compile time?