On Tue, Nov 04, 2003 at 02:00:21PM +0000, Angus Leeming wrote: > Andre Poenitz wrote: > > > On Tue, Nov 04, 2003 at 12:19:25PM +0000, Angus Leeming wrote: > >> I have a container that currently allows the user to alter the Node > >> container. I want to allow the user to be able to alter the Node > >> contents but to not be able to insert, erase Nodes from the vector. > >> > >> What's the best way to proceed? > > > /// The element list is immutable. > > //std::vector<Element> const & elements() const { return > > elements_; } Element const & element(size_t i) const { > > return elements_[i]; } Element & element(size_t i) { return > > elements_[i]; } > > Actually, it's perfectly safe to provide iterators isn't it, so long > as I don't provide access to the storage container itself?
Well... this exposes an implementation detail (type of container) to the outer world. Moreover, people are tempted to use ++ on iterators, whereas not too many poeple would use (&element(3) + 1) So _I_'d prefer the accessor functions. Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)