I have created a MemoryManager
class which is basically a wrapper around two vectors of pointers that manage lifetime of heap-allocated objects.
O
You can implement your own iterator class which handles things the way you prefer. Then your begin() and end() can return instances of that class. For example, your custom iterator could store an integer index and a pointer to the vector itself, thereby making the iterator remain valid even in the face of reallocation.