Boost logo

Boost Users :

Subject: [Boost-users] shared_ptr / auto_ptr
From: Chard (boost_at_[hidden])
Date: 2010-02-23 11:11:13


We've recently been evaluating a move from boost 1.38 to 1.42 [MSVC71], and
we had some code that breaks down to the following:

[1] struct T {};
[2] std::auto_ptr<T> ap;
[3] boost::shared_ptr<T> sp = ap;

Line [3] stopped compiling because of the 'explicit' introduced (in
shared_ptr.hpp) at line [L] (below).

>From smart_ptr/shared_ptr.hpp:

[A] template<class Y>
[B] explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
[C] {
[D] Y * tmp = r.get();
[E] pn = boost::detail::shared_count(r);
[F] boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
[G] }
[H]
[I]#if !defined( BOOST_NO_SFINAE ) && !defined(
BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
[J]
[K] template<class Ap>
[L] explicit shared_ptr( Ap r, typename
boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ),
pn()
[M] {
[N] typename Ap::element_type * tmp = r.get();
[O] pn = boost::detail::shared_count( r );
[P] boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
[Q] }

The fix is trivial, but what I am curious about is:

- the 'explicit' appears to have been removed at version 1.35 (i.e. it was
there at 1.34) and then re-introduced at 1.39. Is there some history to
this?

and

- it looks like our code was falling into the second overload with 1.38 (the
first overload was always explicit); with a fix it will now select the first
overload, so for what case does the second overload now exist?

-- 

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