When making changes to an item inside a Boost multi index, you should use the modify
method exposed by the index object. The modify
method has the following signature:
bool modify(iterator position, Modifier mod);
Where:
position
is an iterator pointing to the item to update
mod
is a functor that accepts a single parameter (the object you want to change).
It returns true
if the modification occurred successfully, or false
if it failed.
When the modify function is run, the functor updates the item you want to change, and then the indexes are all updated.
Example:
class ChangeChannel
{
public:
ChangeSomething(const std::string& newValue):m_newValue(newValue)
{
}
void operator()(Chan &chan)
{
chan.Channel = m_newValue;
}
private:
std::string m_newValue;
};
typedef ChanPtrLista::index<0>::type ChannelIndex;
ChannelIndex& channelIndex = multiIndex.get<0>();
ChannelIndex::iterator it = channelIndex.find("Old Channel Value");
// Set the new channel value!
channelIndex.modify(it, ChangeChannel("New Channel Value"));
You can find more information here.