Boost logo

Boost Users :

From: Konstantin Baumann (boost_at_[hidden])
Date: 2004-02-05 15:01:46


For performance reasons I would like to see something like the following
conversion operators in shared_ptr<T>:

template<class T>
class shared_ptr {
public:
    ...
    template<class S>
    operator shared_ptr<S>&() throw() {
        BOOST_STATIC_ASSERT(T* is convertible to S*);
        return reinterpret_cast<shared_ptr<S>&>(*this);
    }

    template<class S>
    operator const shared_ptr<S>&() throw() const {
        BOOST_STATIC_ASSERT(T* is convertible to S*);
        return reinterpret_cast<const shared_ptr<S>&>(*this);
    }

}; // class shared_ptr<T>

This would mimic the standard conversion from T* to S* without any
performance penalty for shared_ptr<T>.

    Konstantin

"Michele Galante" <m.galante_at_[hidden]> schrieb im Newsbeitrag
news:4020B616.7040900_at_centrosistemi.it...
> > So I have something like this:
> >
> > std::vector<boost::shared_ptr<Base> > BaseVector;
> >
> > void add(boost::shared_ptr<Base>& newOne) {
> > BaseVector.push_back(newOne);
> > }
> >
> > and I call it like this usually :
> > boost::shared_ptr<Derived> p(new Derived);
> > add(p);
> >
>
> I think the problem is you take a reference to the shared_ptr. Try this
way:
>
> void add(boost::shared_ptr<Base> newOne) {
> BaseVector.push_back(newOne);
> }
>
> --
> Michele Galante
> Zucchetti Centro Sistemi SPA
> m.galante_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net