title: Do modern compilers optimize multiplication by 1 and -1
body: <p>If I write</p>
  
  <pre><code>template&lt;int sign&gt;
  inline int add_sign(int x) {
      return sign * x;
  }
  
  template int add_sign&lt;-1&gt;(int x);
  template int add_sign&lt;1&gt;(int x);
  </code></pre>
  
  <p>Are most C++ compilers smart enough to optimize the multiplication by 1 or -1 into some faster operation (no-op or negation)?</p>