
Hi, When using overloaded functions with shared_ptr parameter, overload resolution is often ambigous. It is ambigous in situations where using raw pointers would not be ambigous. I've seen a few workarounds. One workaround is to make one of the two functions a template function, but that does not work in all cases. Another workaround is to just give the functions different names, but you can't do that when the function is a CTOR. Well, to my surprise, I found a post from Artyom Borodkin from last December that explains how it can be permanently fixed in boost itself! I thought there was no way I would ever resolve this. http://lists.boost.org/Archives/boost/2005/12/97817.php I went ahead and tested his suggestion by modifying the boost source (I had to change slightly what he wrote), and it worked! I changed this constructor: template<class Y> shared_ptr(shared_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws { } to this: template<class Y> shared_ptr(shared_ptr<Y> const & r, typename enable_if<typename is_convertible<Y*, T*>::type, void*>::type = 0): px(r.px), pn(r.pn) // never throws { } So to iterate what Artyom said, why would we not want to do this?! Thanks, Phillip Hellewell

On 8/18/06, Phillip Hellewell <sshock@gmail.com> wrote:
to this:
template<class Y> shared_ptr(shared_ptr<Y> const & r, typename enable_if<typename is_convertible<Y*, T*>::type, void*>::type = 0): px(r.px), pn(r.pn) // never throws { }
I forgot to mention, you have to include these two headers in shared_ptr.hpp. #include <boost/type_traits.hpp> #include <boost/utility/enable_if.hpp> (But you probably already figured that out). Phillip Hellewell

Phillip Hellewell wrote:
On 8/18/06, Phillip Hellewell <sshock@gmail.com> wrote:
to this:
template<class Y> shared_ptr(shared_ptr<Y> const & r, typename enable_if<typename is_convertible<Y*, T*>::type, void*>::type = 0): px(r.px), pn(r.pn) // never throws { }
I forgot to mention, you have to include these two headers in shared_ptr.hpp.
#include <boost/type_traits.hpp> #include <boost/utility/enable_if.hpp>
Yes, and this is why the change isn't the no-brainer it seems at first. shared_ptr is a critical Boost component that has to work on every compiler supported by Boost (and a few unsupported ones.) So I tend to avoid problematic constructs and unnecessary dependencies. I agree that the feature is useful and will try to find a relatively painless way to incorporate it.
participants (2)
-
Peter Dimov
-
Phillip Hellewell