[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Steinar Bang <sb_at_dod.no>
Date: Wed, 13 Oct 2010 22:16:08 +0200

>>>>> "Hyrum K. Wright" <hyrum_wright_at_mail.utexas.edu>:

> At this point, it's my turn to get confused. I'm speaking
> specifically of cases where we return STL classes. Brane's earlier
> suggestion to create an implicit bool conversion works fine for our
> custom classes. The problem I'm trying to solve is "how does one
> return the equivalent of '(const char *) NULL' in an std::string?"
> It's a this point that pointers start coming into play, because a NULL
> std::string * is quite feasible, whereas a NULL std::string isn't.

Ah, ok. That was at a different part of the thread... which I avoided
responding to because I have any good answers at hand. :-)

Do you need the distrinction between an empty string and a NULL?

If not then I would return an empty string for a NULL on the C side.

There's also the consideration that some std::string implementations are
deep copying (the gcc version uses refcounting (or at least used to do
so), but the VC++ one used to use deep copying. I'm not sure if that
still is the case).

Then maybe what you want to return is const std::string& (which leaves
you with the headache of managing the life cycle of the std::string, so
maybe not... though... you have the context of the wrapper class and
could cache them lazily there. That would increase the footprint of the
wrapper, though).
Received on 2010-10-13 22:16:58 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.