   Returning containers from a method.
  I have a bunch of objects that currently return a containers for a caller to operate on.e.g.class Foo{public:    const std::vector<int> &GetThings() const;};Ignoring for the moment whether I should be returning a copy rather than a const reference (in my real scenario, it's not a vector of int's, but a vector of objects that could be tens of kilobytes), what's "the right" way to do this?  The callers of these functions generally just iterate over the items, and don't really care much about what the container implementation is.So having a std::vector<int>& return value seems to expose too much of the innards of the class.  Would it be better to have something likeclass Foo{public:    typedef std::vector<int> things_container;    const things_container &GetThings() const;};So a caller can doconst Foo::things_container &things = theFoo.GetThings();... and no longer knows/cares what the container implementation is.Or how about not returning the container, but just the begin/end iterators...class Foo{public:    typedef std::vector<int>::const_iterator things_iterator;    thing_iterator GetThingsBegin() const;    thing_iterator GetThingsEnds() const;};Any guidelines either way?   
  Just out of curiosity, what are the 'things', and what do you need to do with them?It seems the simple fact that you require external access to a container that is private to a class should raise a red flag. In other words, the question isn't so much what is the best way to grant this access, but why it's necessary to grant access in the first place.Anyway, with some more detail about what you're actually doing, I'm sure the gurus here will be able to suggest an appropriate solution.   ;  0) Like jyk said.1) I'd go with the iterators, but return them both at once, in a std::pair. (See for example std::multimap::equal_range().)   ;  It's basically the syntax tree for a programming language.  So in my example, Foo might represent a class definition, and the "Things" might be the methods on that class (the methods in turn would have a list of parameters, list of local variable declarations, and list of code statements).A client, given a class definition, might want to ask what the methods are.A client, given a method, might want to find out what the local variable declarations are.A client, given a local variable declaration, might want to see if it is an array, and if so, get a list of initialization values for that array.and so on...   