title: Best way to merge multiple STL containers, removing duplicate elements?
body: <p>I have two STL containers that I want to merge, removing any elements that appear more than once.  For example:</p>
  
  <pre><code>typedef std::list&lt;int&gt; container;
  container c1;
  container c2;
  
  c1.push_back(1);
  c1.push_back(2);
  c1.push_back(3);
  
  c2.push_back(2);
  c2.push_back(3);
  c2.push_back(4);
  
  container c3 = unique_merge(c1, c2);
  // c3 now contains the following 4 elements:
  //   1, 2, 3, 4
  </code></pre>
  
  <p>std::unique seems to be for adjacent elements only, and in my case the containers could be in any order.  I could do some <strong>std::set</strong> trickery I guess:</p>
  
  <pre><code>container unique_merge(const container&amp; c1, const container&amp; c2)
  {
      std::set&lt;container::value_type&gt; s;
      BOOST_FOREACH(const container::value_type&amp; val, c1)
          s.insert(val);
      BOOST_FOREACH(const container::value_type&amp; val, c2)
          s.insert(val);
      return container(s.begin(), s.end());
  }
  </code></pre>
  
  <p>Is there a better way or have I missed something bleeding obvious?</p>