Re: [Libxmlplusplus-general] const std::string& return types.



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Le Vendredi 15 Novembre 2002 14:29, Murray Cumming a écrit :
> I am very uncomfortable with function signatures such as this:
> const std::string& Node::name() const;
>
> because
> a) It is untargetted optimisation, and it's too early for that.

True. It can be seen as a way of 'saying' : this method returns the exact 
content of an internal field, but you cannot change it.

> b) It makes orphaned references possible.
> c) std::string can be implemented with reference-counting to make
> copying more efficient - I believe that newer versions of libstdc++ do
> this.

Do you mean the one given with g++ 3.x ? well I thought it was not.
Moreover can we stat that all libxml++ will use this implementation of 
std::string ?


>
> Christophe, if you agree then I will change all these methods to look
> like this instead:
> std::string get_name() const;


Well, I'm (for now) half convinced only. since we return a const referenced 
object, it will force the calling code either to copy the string immediately, 
either to call a const function on it (which is fine in a non threaded 
context).
And keeping an orphan reference on it is, in my mind, more a mistake of the 
lib user than a lack of robustess of the lib. The use of const references 
does not, usually, to this.
So although I quite agree your arguments, I'm not sure it's *that* needed.

I'm waiting forward for your comments,

Christophe

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3U/z0ACgkQB+sU3TyOQjCEnACgoTSABMatjHL+wE04sCHx+4U8
/dAAn2HVa9hmHtDFjzxfyQBu2kKsqzQO
=eb6a
-----END PGP SIGNATURE-----





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]