Category : insert

I understand the general differences between insert and emplace_back for std::vector and std::list. Normally, I would just use emplace_back any time I want to append an element. For some applications, I need to append the element and have an iterator pointing to that newly appended element. So typically, I’ve been doing something like: // for ..

Read more

In Item 41 from Effective Modern C++, the following is one of the situations that give a chance for emplacement functions to be more performant than the insertion conterparts: The container is unlikely to reject the new value as a duplicate the reason being that, given the arguments to the constructor of the oject whose ..

Read more

I have a function: void DBMAP::addM(Volkov_1* b) { setMAP.insert(pair<int, Volkov_1*>(*b->x, b)); } This function passes data from set to multimap. And she copes with her duty, but there is a moment of double ownership. It is necessary not to pass the existing pointer, but to copy. I don’t understand how to implement this. I ask ..

Read more