Boost C++ Libraries: Ticket #41: smart_ptr: (auto_ptr) constructor https://svn.boost.org/trac10/ticket/41 <pre class="wiki">I'm wondering why the smart_ptr's (auto_ptr) constructor is defined as explicit? In smart_ptr's documentation this constructor is not explicit: --cut-- template&lt;typename Y&gt; shared_ptr(std::auto_ptr&lt;Y&gt;&amp; r); --cut-- but in source: --cut-- template&lt;typename Y&gt; explicit shared_ptr(std::auto_ptr&lt;Y&gt;&amp; r) { pn = new long(1); // may throw px = r.release(); // fix: moved here to stop leak if new throws } --cut-- explicit shared_ptr(std::auto_ptr&lt;T&gt;&amp; r) { pn = new long(1); // may throw px = r.release(); // fix: moved here to stop leak if new throws } --cut-- It would be nice to do for example following without initializing an shared_ptr instance by myself: // START void func_that_eats_both_ap_and_sp(const boost::shared_ptr&lt;int&gt;&amp; sp) { // ... } int main(void) { std::auto_ptr&lt;int&gt; ap(0); func_that_eats_both_ap_and_sp(ap); } // END auto_ptr's constructor should not be the reason why this is defined as it is, since it is defined as explicit... -d-elf </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/41 Trac 1.4.3 Peter Dimov Wed, 28 May 2003 12:11:00 GMT status changed https://svn.boost.org/trac10/ticket/41#comment:1 https://svn.boost.org/trac10/ticket/41#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=305912 The constructor is explicit for safety reasons since it modifies the source auto_ptr. </pre> Ticket