title: finding elements of set in a map
body: <p>I have two maps, <code>tk1</code> and <code>tk2</code> with the following structure:</p>
  
  <pre><code>std::map&lt;std::string, double&gt;tk1;
  std::map&lt;std::string, double&gt;tk2;
  </code></pre>
  
  <p><code>tk1</code> contains the following data:</p>
  
  <pre><code>    2011-01-03 2200
      2011-01-04 2209
      2011-01-05 2300
  </code></pre>
  
  <p>and <code>tk2</code> contains the following data:</p>
  
  <pre><code>2011-01-03 2450
  2011-01-04 2465
  2011-01-06 2476
  2011-01-07 2457
  </code></pre>
  
  <p>I have created a set that contains the dates as strings as in</p>
  
  <pre><code>std::set&lt;std::string&gt;dateset;
  std::set&lt;std::string&gt;new_dateset;
  </code></pre>
  
  <p>I created it by iterating through the 2 maps and inserting into the set as in</p>
  
  <pre><code>dateset.insert(it-&gt;first);
  </code></pre>
  
  <p><code>dateset</code> has the following values:</p>
  
  <pre><code>2011-01-03
  2011-01-04
  2011-01-05
  2011-01-06
  2011-01-07
  </code></pre>
  
  <p>I want to populate new_dateset so it only contains the dates that are in both <code>tk1</code> and <code>tk2</code>, i.e. new_dateset should contain only</p>
  
  <pre><code>2011-01-03
  2011-01-04
  </code></pre>
  
  <p>I wrote the following:</p>
  
  <pre><code>std::set&lt;std::string&gt;::iterator it1=dateset.begin(), end1=dateset.end();
  std::map&lt;std::string, double&gt;::iterator it2=tk1.begin(), end2=tk1.end();
  std::map&lt;std::string, double&gt;::iterator it3=tk2.begin(), end3=tk2.end();
  while (it1 != end1) {
  if (it2-&gt;first == *it1) 
  new_dateset.insert(it2-&gt;first);
  ++it1;
  }
  </code></pre>
  
  <p>but obviously I am not doing it correctly. Can someone suggest the best way to do this.</p>