Andre said:
Depends on the container, of course. list certainly doesn't require the
const. set may, and map doesn't. (It may be a pair<const K, V>, but the
pair itself isn't const)
I thought we were talking strictly about sets in the previous discussion.
I'd prefer to use the phrase 'stable' (persistent?).
Actually, after reading chapter 6 of TC++SL, it seems vectors are the only
containers that will present a problem when they are resized. Of course
any reference to an element that is erased, popped, or list::remove()d,
will present a problem. Inserts are a different story than pushes, and
iterators do not behave exactly as do references. Iterators are more
easily invalidated.
Bad practice? Not too sure about that. However, one would be encouraged
to research the appropriate iterator and reference lifetimes of the
various containers that you are using...
I guess it depends on what you know will happen to the container in the
future. I actually have code that keeps a reference to a vector (IIRC - it
may be a boots::array<>, which would be better). Since I don't intend to
change the size of the vector after it's allocated, and the number of
dimensions in 3-space is unlikely to change in the foreseeable future, I'm
probably pretty safe.