at a time, I created a pointer point to std::vector , then I performed some push_back , reserve , resize operation for this vector, after such operations it is safe to compare the pointer with the address of this vector to check if the pointer points to this vector, because there may be some reallocation of memory.
eg
std::vector<int> vec; vector<int>* pVec = &vec; vec.reserve(10000); assert(pVec == &vec); vec = anotherVec; assert(pVec == &vec);
what's more, is it safe to compare a pointer to the first value of a vector? eg:
std::vector<int> vec(1,0); int* p = &vec[0];
As I myself experienced, it seems that the first situation is safe and the second is not, but I can’t be sure.
source share