There is an assertion to warn you in debug mode if this is accidentally used. It is a design decision whether the class should actually support this use case where the client code attempts to call removeElement() on arbitrary indices/ID.
Ah, I just overlooked it. I expected it in the removeElement method, but it was in the clear method.
It would appear to me that the intention is that a client class would use addElement(), store an index/ID, and then use getElement() when necessary, finally using removeElement() when finished.
Your correct. A warning when I accidentally do something wrong is all I need, I just didn't see that it's already there.
I think Container is too generic. To me, it is some kind of handle system, so maybe a name like HandleRepository?
Yes, that's better, thanks!