dsp*_*pyz 3 c++ compiler-construction templates sign compiler-optimization
如果我写
template<int sign>
inline int add_sign(int x) {
return sign * x;
}
template int add_sign<-1>(int x);
template int add_sign<1>(int x);
Run Code Online (Sandbox Code Playgroud)
大多数 C++ 编译器是否足够聪明,可以将乘法乘以 1 或 -1 优化为更快的运算(无操作或否定)?