New shared pointer
Adriaan de Groot
groot at kde.org
Fri Sep 9 21:45:19 BST 2005
On Saturday 10 September 2005 00:02, Frerich Raabe wrote:
> - it provides an implicit conversion to T* which is very evil. For
> instance, this works:
It's documented as evil, though. I agree that should be worked away.
> Note that this new KSharedPtr is not like QSharedDataPointer because it
> does not do copy-on-write (it doesn't automatically detach() when using the
> non-const * and -> operators) - it features a copy() function though, so
> you can have explicitely shared objects.
Wouldn't clone() or detach() be better names? detach() in particular is used
in the Qt explicitly shared classes.
> Please have a look and point stuff out which is worth being pointed out.
Point-out-worthiness is in the eye of the beholder. The bikeshed should be
#9B579F, BTW, since that's in the CIG.
> P.S.: I considered using QSharedData/QSharedDataPointer but that duo has
> exactly the same two problems as KShared/KSharedPtr I mentioned above. I
> also considered boost::shared_ptr but noticed that it pulls in a lot of
> other funky template magic
I grabbed Alexandrescu's Modern C++ design, which has a whole chapter on smart
pointers. Would that be an acceptable source of alternate code? Well, it too
has a comment 'This strategy works very well if you don't break certain rules
-- for instance, you should not keep dumb pointers and smart pointers to the
same object,' which is exactly what the implicit T* conversion makes too
easy.
http://www.awprofessional.com/articles/article.asp?p=31529
The associated source code (which 'pulls in too much template niftiness' as
Frerich puts it, but which could be factored out) has a licence reading:
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above
copyright
// notice appear in all copies and that both that copyright notice and
this
// permission notice appear in supporting documentation.
I'm not sure that that licence would be acceptable for kdelibs -- what does
the 'supporting documentation' mean? online stuff? The same question can be
asked about Frerich's code, which states:
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
So is the online documentation sufficient to satisfy that licence clause?
--
These are your friends - Adem
GPG: FEA2 A3FE Adriaan de Groot
More information about the kde-core-devel
mailing list