Boost logo

Boost :

From: Matthew D. Langston (langston_at_[hidden])
Date: 1999-10-05 17:42:27

I've attached a small patch to `smart_ptr.hpp' which enables all of the
functionality of smart_ptr for those compilers which support member
templates, even if those compilers currently lack support for member
template friends.

The current (i.e. non-patched) smart_ptr must forgo all of the benefits
of member templates even if the compiler supports them. This seemed too
restrictive to me. My patch allows users of smart_ptr to reap the
benefits of all possible implicit type conversions even if the compiler
doesn't support member template friends.

If you examine the patch, you will see that the way I accomplish this is
through the use of a tasteless hack - I conditionally make all of the
private parts of smart_ptr public (depending on whether or not the
compiler supports member template friends).

I wholeheartedly agree with the comments in `config.hpp' that
"configuration headers are a necessary evil rather than a desirable
feature". However, since the boost library has chosen to use a
configuration header to "support only compilers which appear on their
way to becoming C++ Standard compliant", my patch seems to be in the
spirit of allowing smart_ptr to support all of those features that the
compiler has to offer.

Please note that the patch preserves the pure interface of smart_ptr in
the absence of `config.hpp', as the comments in this file dictate. Only
if `config.hpp' defines BOOST_NO_MEMBER_TEMPLATE_FRIENDS do smart_ptr's
private parts become public.

If the boost developers don't want to use my patch, I would completely
understand. The only reason I created it was to allow myself, and my
users, to use the full functionality of smart_ptr when using egcs 1.1.2
and gcc 2.95.1, so even if the patch doesn't end up as part of the boost
library, perhaps it will be helpful to those users using smart_ptr in
the real world.

Enjoy :-)

Matthew D. Langston
SLD, Stanford Linear Accelerator Center

--- smart_ptr.hpp.lf Thu Sep 30 12:11:21 1999
+++ smart_ptr.hpp Tue Oct 5 14:54:05 1999
@@ -117,8 +117,7 @@
 #if !defined( BOOST_NMEMBER_TEMPLATES ) /* old name for compatibility */ \
- && !defined( BOOST_NO_MEMBER_TEMPLATES ) \
    template<typename Y>
       shared_ptr(const shared_ptr<Y>& r) throw() : px(r.px) {
@@ -180,7 +179,11 @@
    void swap(shared_ptr<T>& other) throw()
        { std::swap(px,other.px); std::swap(pn,; }
+// Tasteless as this may seem, this allows member templates to work in
+// the absence of member templates friends.
    T* px; // contained pointer
    long* pn; // ptr to reference counter

Boost list run by bdawes at, gregod at, cpdaniel at, john at