On Sat, Mar 29, 2008 at 02:01:26PM -0500, Bo Peng wrote:
> >  -       EmbeddedFile const * findFile(std::string const & filename) const;
> >  -       EmbeddedFile * findFile(std::string const & filename);
> >  +       const_iterator findFile(std::string const & filename) const;
> >  +       iterator findFile(std::string const & filename);
> 
> Of course. :-)

Well, I don't have a strong opinion here (i.e. "I don't care much"), but
I'd like to point out that there is not a canonical solution for this
case:

Returning an iterator exposes quite some internal detail and makes
decoupling more difficult.

Secondly, it suggests that the return value is usable for some kind of
'iteration', something that is not exactly what we usually want to do
with it.

The third "problem" it shares with the original pointer approach: It's
unclear to the outside how long the returned value is valid and under
which circumstances it gets invalidated. Even worse, there is no way to
check whether the value is still valid (after it has e.g. been stored a
while somewhere).

An approach that does not have this problem is the good old "integer
offset" one, i.e. a   int numberOfItems(); itemAt(int);  pair of
functions. 

Andre'

Reply via email to