>>>>> "Hyrum K. Wright" <hyrum_wri...@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).


Reply via email to