Boost logo

Boost :

From: Borgerding, Mark A. (MarkAB_at_[hidden])
Date: 2000-07-28 07:35:05


A ptr assignment in the template constructor can solve the problem of type
relation:

    template<typename Y>
    shared_ptr(const shared_ptr<Y>& r) throw() : px(r.get()) {
      T * dummyptr = r.get();
      // this will not compile if Y* cannot be made a T*
      // a good compiler might be able to get rid of the runtime cost
altogether
      ++*(pn = reinterpret_cast<const shared_ptr<T>&>( r ).pn);
   }

> -----Original Message-----
> From: David Abrahams [mailto:abrahams_at_[hidden]]
> Sent: Friday, July 28, 2000 3:52 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] shared_ptr implementation without
> template friends
>
>
> Unfortunately, the solution proposed below is unacceptable,
> because it would
> allow construction of shared_ptr<X> from shared_ptr<Y> even
> where X and Y
> are unrelated types. That code should only compile where X
> and Y are the
> same type or where Y is derived from X.
>
> -Dave
>
> ----- Original Message -----
> From: "Gernot Neppert" <gn_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Thursday, July 27, 2000 10:05 AM
> Subject: [boost] shared_ptr implementation without template friends
>
>
> > Hi!
> > I've been using the template class "shared_ptr" with a compiler that
> doesn't
> > support template friend declarations (You will have guessed
> already: It's
> > Microsoft VC++ 6).
> > So, the symbol BOOST_NO_MEMBER_TEMPLATE_FRIENDS is defined,
> and everything
> > works fine - except that the members of the class become
> publicly exposed.
> > This is really annoying, so I came up with a proposal. Although it
> > introduces an ugly reinterpret_cast, this is confined to two methods
> > (templated ctor and assignment operator), whereas the
> additional "public:"
> > affected the entire class. Here's the code for the ctor:
> >
> > #if defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS )
> > template<typename Y>
> > shared_ptr(const shared_ptr<Y>& r) throw() : px(r.get()) {
> > ++*(pn = reinterpret_cast<const shared_ptr<T>&>( r ).pn);
> > }
> > #else // original version
> >
> > template<typename Y>
> > shared_ptr(const shared_ptr<Y>& r) throw() : px(r.px) {
> > ++*(pn = r.pn);
> > }
> >
> > #endif
>
>
>
> --------------------------------------------------------------
> ------<e|-
> Download iPlanet Web Server, FastTrack Edition 4.1 for FREE,
> and start publishing dynamic web pages today!
> http://click.egroups.com/1/7540/4/_/9351/_/964773110/
> --------------------------------------------------------------
> ------|e>-
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk