If I write
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);
Are most C++ compilers smart enough to optimize the multiplication by 1 or -1 into some faster operation (no-op or negation)?