tags:

views:

50

answers:

1

I have a

multimap<key1,pair<key2, value2>>

I want to change value2 in this multimap.

typedef std::pair<int, int> comp_buf_pair; //pair<comp_t, dij>
typedef std::pair<int, comp_buf_pair> node_buf_pair;
typedef std::multimap<int, comp_buf_pair> buf_map; //key=PE, value = pair<comp_t, dij>
typedef buf_map::iterator It_buf;


buf_map bufsz_map;

bufsz_map.insert(node_buf_pair(target(*ei,g), comp_buf_pair(comp_t[target(*ei,g)], dij)));


for(It_buf it = bufsz_map.equal_range(*u_iter).first; it!= bufsz_map.equal_range(*u_iter).second;)
{
    comp_buf_pair it1 = it->second;
    if(it1.first < c_i)
    {
        std::cout << it1.first << " : " << it1.second << std::endl;
        old_c_i = it1.first;
        old_dij = it1.second;
        updated_dij = (c_i-old_c_i) + old_dij;

        // I would like to erase the it1.second value and add the updated_dij value in the bufsz_map
    }
}

What would be a better way to do it?

+2  A: 

The statement it->second.second = updated_dij; will overwrite the old value. Since you don't change the key field or indicate what a new key would be, this seems sufficient.

Is this what you are looking for or do you want to insert updated_dij under a new key and delete the old key?

academicRobot
This solves my problem :)
vivekv80