If I have a std::vector<std::vector<char>>
Where the following is true:
- The inner vectors's size is never changed
- The outer vector's size is changed with insertions and removals
Can I take an address into the inner vector like this, use it after modifying the outer vector, and be safe?
std::vector<std::vector<char>> buffer;
#include <code that inserts into "buffer" uhhh 10 vectors with 100 char each>
char * ch = buffer[5].data();
// example of code that never erases/resizes the vector "ch" is pointing into...
// ... BUT will remove/insert vectors around it, prompting "buffer" to reallocate
buffer.erase(buffer.begin(), buffer.begin() + 4);
buffer.shrink_to_fit();
buffer.insert(buffer.begin(), std::vector<char>(1));
assert(buffer[1].data() == ch); // the 5th inner-vector moved to index 1
printf("how is this bit%c?", *ch); // but hopefully "ch" is still valid?