Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr / auto_ptr
From: Baptiste Lepilleur (baptiste.lepilleur_at_[hidden])
Date: 2010-02-23 15:55:10


2010/2/23 Chard <boost_at_hazlewoods.eu>

> [...]

>From smart_ptr/shared_ptr.hpp:
>
> [A] template<class Y>
> [B] explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
>

By the way, shouldn't this constructor take std::auto_ptr by value instead
of by reference. I remember being forced to introduce a local variable with
the example below (was with sunstudio 12, default STL if I remember
correctly). I think this was caused because you can not bind a temporary
object to a non const reference.

struct T {};
std::auto_ptr<T> factory();

void failedCompile() {
   boost::shared_ptr<T> p( factory() );
}

// Needed to be modified as:
void compile() {
   std::auto_ptr<T> temp = factory();
   boost::shared_ptr<T> p( temp );
}

Baptiste.



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