How to avoid if cond. for stack operation
<p>I have created a stack class which holds std::vector. I have written stack operation like pop() and exch() like</p>

<pre><code>int Stack::pop() 
{
  if (v.size() &lt; 0)
    throw("Error : Stack Underflow");

  int tos = v.back();
  stack.erase(v.end()-1);
  return tos;
}

void Stack::exch()  // Exchange top 2 element
{
  if (v.size() &lt; 2)
    throw("Error : Stack Underflow");

  size_t n = v.size();
  int tmp = v[n-1];
  v[n-1] = v[n-2];
  v[n-2] = tmp;
}
</code></pre>

<p>My application consist of lot of 'pop()' &amp; 'exch()' operations. But due to 'if' conditions the performance is little bit slow.
Can you tell me how to avoid 'if' conditions ?
Is there any way Or work around to avoid 'if'.</p>

<p>Thanks in advance.</p>

<p>Thanks,
Nilesh</p>
