Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-18 10:45:34


From: "Andrew R. Thomas-Cramer" <artc_at_[hidden]>
> Thanks very much for your response.
>
> I think these two particular implicit conversions are very important to
most
> programmers. Support for the conversion from shared_ptr<T> to
shared_ptr<const
> T> was not obvious to me. Perhaps the smart pointer documentation could
> explicitly refer to these conversions, and provide examples?

Yes, you are right, the documentation doesn't mention the conversions. We'll
need to update the introduction paragraph to explain that shared_ptr<T> can
convert to shared_ptr<U> whenever T* can convert to U*. Thanks for the
feedback. (I've CCed the boost list.)

--
Peter Dimov
Multi Media Ltd.
> ----- Original Message -----
> From: "Peter Dimov" <pdimov_at_[hidden]>
> Newsgroups: comp.lang.c++.moderated
> Sent: Wednesday, April 17, 2002 3:09 AM
> Subject: Re: Smart pointers (boost or not): const-checking, polymorphism
>
>
> > "Andrew R. Thomas-Cramer" <artc_at_[hidden]> wrote in message
> news:<3cbb189d$0$30311$272ea4a1_at_[hidden]>...
> > > I'm considering the use of some reference-counting smart pointer
classes for
> > > an existing company library. I'm aware of boost::shared_ptr, and will
> > > probably either use it directly or as the representation of
library-specific
> > > smart-pointer classes.
> > >
> > > Let shared_ptr<T> be some reference-counting smart pointer type,
either in
> > > the boost namespace or not.
> > >
> > > With raw pointers, I can const-qualify the pointer:
> > >     int foo( const T * p );
> >
> > It is not the pointer being const-qualified in the above example, but
> > the pointed-to type. A const-qualified pointer would be "T * const."
> >
> > > How should this be done in a similar method accepting a smart pointer?
> >
> > shared_ptr<T const>.
> >
> > > Let class U extend T. With raw pointers, I can pass a single pointer
to both
> > > these methods:
> > >     int foo( const T * p );
> > >     int bar( const U * p );
> > > How should this be done in similar methods accepting smart pointers?
> >
> > boost::shared_ptr<U> automatically converts to boost::shared_ptr<T>.
> >
> >       [ Send an empty e-mail to c++-help_at_[hidden] for info ]
> >       [ about comp.lang.c++.moderated. First time posters: do this! ]
>
>

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