Keeping separate pointers to container items
<p>I am struggling a bit to understand the best way to safely store a reference or pointer to an item in a container without risking that the pointer could get invalidated.</p>

<p>With <code>std::vector</code> this seems like a bad idea in general, since you never know when your item might be moved to a new memory location as <code>vector</code> re-allocates. Is there such a way?</p>

<p>With <code>list</code> and <code>deque</code> is this instead a better option? From what I understand, items in these collections are not moved around, so could I just take a pointer to the memory address of a specific element?</p>

<p>I'm coming from Objective-C where this sort of thing is easy and common with all its containers since Objective-C pretty much uses pointers for everything so tossing them around and copying them is quite commonplace.</p>
