title: How to compute in-place set difference of two multisets?
body: <p>Suppose I have two multisets.  I want to remove all elements that occur in the second multiset from the first multiset, <em>respecting the number of times each element occurs in each multiset</em>.  For example, If multiset <code>a</code> contains <code>1</code> five times, and multiset <code>b</code> two times, when I compute <code>a -= b</code>, only two instances of <code>1</code> should be removed from <code>a</code>.</p>
  
  <p>Here is some code that accomplishes this:</p>
  
  <pre><code> multiset&lt;int&gt; a;
   multiset&lt;int&gt; b;
  
   // remove all items that occur in b from a, respecting count ("a -= b")
   for (multiset&lt;int&gt;::iterator i = b.begin(); i != b.end(); i++) {
      if (a.count(*i) &lt; 1) {
         // error 
      }
      // a.erase(*i) would remove ALL elements equal to *i from a, but we 
      // only want to remove one.  a.find(*i) gives an iterator to the first
      // occurrence of *i in a.
      a.erase(a.find(*i));
    }
  </code></pre>
  
  <p>Surely there's a better / more idiomatic way?</p>