title: Swap two values on a stack
body: <p>I want to swap the two values on the top of a <code>std::stack&lt;double&gt;</code>. Is there a better way than the following to do that ?</p>
  
  <pre><code>void swap_top(std::stack&lt;double&gt;&amp; stack)
  {
    double a = stack.top();
    stack.pop();
    double b = stack.top();
    stack.pop();
    stack.push(a);
    stack.push(b);
  }
  </code></pre>