I am trying to use the Boost MultiIndex container in my simulation. My knowledge of C ++ syntax is very weak, and I am concerned that I am deleting an element from a container or deleting it from memory incorrectly. I also need to change the elements, and I was hoping to validate the syntax and basic philosophy here too.
// main.cpp ... #include <boost/multi_index_container.hpp>
My questions
- In the MultiIdex container,
allHosts of shared_ptrs to Host objects calls allHosts.erase( it ) on the iterator for the shared_ptr object enough to delete the object permanently and free it from memory? It looks like you are removing shared_ptr from the container. - The
allHosts container has one functional index that relies on the host identifier. If I present an ordered second index that calls a member function (Host :: getAge ()), where the age changes during the simulation, is the index always updated when I access it? - What is the difference between using MultiIndex to change the age of a base object compared to the approach I show above?
- I am vaguely confused about what is supposed / required to be persistent in MultiIndex.
Thanks in advance.
Update
Here's my attempt to get modify syntax based on what I see in the Boost related example .
struct update_age { update_age():(){} // have no idea what this really does... elicits error void operator() (boost::shared_ptr<Host> ptr) { ptr->incrementAge(); // incrementAge() is a member function of class Host } };
and then in modifyHost , I would have hmap.modify(it,update_age) . Even if by some miracle this turns out to be correct, I would like to get some explanation of what is happening.
c ++ boost
Sarah
source share