<p>I'm trying to do the following without too much special case code to deal with invalidated POSITIONs etc:</p>

<p>What's the best way to fill in the blanks?</p>

<pre><code>void DeleteUnreferencedRecords(CAtlMap&lt;Record&gt;&amp; records)
{
   for(____;____;____)
   {
      if( NotReferencedElsewhere(record) )
      {
        // Delete record
        _______;
      }
   }
}
</code></pre>

My first thoughts would be the save the current POSITION before calling
```
GetNext
```
, then, if you delete the element you can reset it.  However, perhaps the safest way would be to create a new map containing the elements you want to keep, else you could be relying on how the internal implementation of POSITION works.