title: Elegant way to express shift left OR right in template
body: <p>I currently have a template function which, depending on its template parameters A and B, may shift a value either left or right:</p>
  
  <pre><code>template &lt;int A, int B&gt; void f(X) {
  // ...
  if (A &gt;= B)
  {
    SetValue(X &lt;&lt; (A-B));
  }
  else // (A &lt; B)
  {
    SetValue(X &gt;&gt; (B-A));
  }
  </code></pre>
  
  <p>When I instantiate the template for <code>A&lt;B</code>, I get a warning for a negative shift right on the (unreachable) first branch, and else I get a warning for a negative shift left on the first branch. Our codebase is warning-free so this isn't acceptable. Is there a concise, readable alternative to these two shift statements?</p>
  
  <p>Similar questions (e.g. <a href="https://stackoverflow.com/questions/8009040/dynamically-shift-left-or-right">Dynamically shift left OR right</a>) don't have this spurious warning as the shift distance is a runtime variable there.</p>