Get last/newly added element in std::set?

Set::insert returns an iterator to the newly inserted item. Hold on to that iterator if you're interested in that item.

If you still have the old set, compute the set_difference between them. Otherwise, you can't. The std::set doesn't retain any information about when the element is inserted.

Use a std::vector (and insert elements by push_back only) if you need to keep that information.

Sets are different from lists and vectors in that they are unordered. Adding an object to the set will put it somewhere in the set, but not necessarily at the end. See cplusplus/set for more information about the way a set stores its information.

IMHO, easiest could be storing the last inserted value in a variable, see the "Memento" design pattern. Another way is to use another data structure - maybe some sort of stack.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions