Yes, this should always be optimized.
Even if it is not, I feel that the cost of std::cos greatly outshine the cost of the conditional.
If for some reason it is not optimized, use specialized template specialization to force the branch at compile time.
source share