I am using a vector but for a number of reasons, referring to individual elements using pointers. The problem is that when I add elements, the vector resizes and may move the elements to another larger memory address. This invalidates my pointers.
To avoid the reallocation, I call vector<T>::reserve before using the vector. However there are instances where I have not reserved enough space. In this instance I would like the vector to assert or throw an exception rather than trying to silently resize.
Is there any way to do this using vectors or another data structure? Can I use C99 variable length arrays and if so, how do I initialized one to the correct length in my constructor? Or do I need to roll out my own explicitly resizable vector?