I want to perform in place modification to a std::map while iterating over it
<p>I need to know the best way to do the in place modification to the map without taking a local copy of the values modified and then pushing it again into the original map.</p>

<p>I have detailed the snippet below that explains the problem:        </p>

<pre><code>#include &lt;string&gt;
#include &lt;map&gt;
struct EmployeeKey
{
    std::string name;
    int amount;
    int age;
};

struct EmployeeDetail
{
    std::string dept;
    int section;
    int salary;
};

bool compareByNameAge(const std::string&amp; name,
                      const int&amp; age,
                      const EmployeeKey&amp; key )
{
    return name &gt; key.name &amp;&amp; age &gt; key.age;
}

typedef std::map&lt;EmployeeKey, EmployeeDetail&gt; EmployeeMap;

int main()
{
    EmployeeMap eMap;
    // insert entries to the map
    int age = 10;
    std::string name = "John";

    EmployeeMap transformMap;
    foreach( iter, eMap )
    {
        if ( compareByNameAge(name, age, iter-&gt;first) )
        {
            //**This is what i want to avoid.......
            // take a copy of the data modified
            // push it in a new map.
            EmployeeDetail det = iter-&gt;second;
            det.salary = 1000;
            transformMap[iter-&gt;first] = det;
        }
    }

    //** Also, i need to avoid too...  
    // do the cpy of the modified values   
    // from the transform map to the   
    // original map  
    foreach( iter1, transformMap )  
        eMap[iter1-&gt;first] = iter1-&gt;second;
}  
</code></pre>
