Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-14 05:55:59


Ion Gaztañaga wrote:
>>> * Is this gcc error correct? Revising a bit ADL + template issues (a
>>> fairly complicated logic that should be removed from C++, in my
>>> opinion) I think that gcc is right.
>>
>> Questionable. The problem is that for static_pointer_cast<int> to be
>> valid, static_pointer_cast must be known to be a template. It is
>> understandable why g++ rejects it without a declaration, but I'm not
>> sure whether this is conforming now, much less whether it'd be
>> conforming tomorrow if there are open core issues for this case.
>
> I think I should post this to c.s.c++ to see if this call should kick
> ADL. If so, I will report a bug to the gcc mailing list. Anyway,
> static_pointer_cast is not a portable ADL function in Boost. What
> should
> we do? Declare an overload taking an additional dummy parameter to
> deduce the return type?
>
> template<class Source, class Target>
> smart_ptr<Target> static_pointer_cast
> (const smart_ptr<Source> &s, const Target &);
>
> so that the ADL call is:
>
> Pointer p;
>
> IntPtr ip = static_pointer_cast(p, int());

We used to write

 template<class Source, class Target>
 smart_ptr<Target> static_pointer_cast
    (const smart_ptr<Source> &s, Target * = 0);

 IntPtr ip = static_pointer_cast(p, (int*)0);

when MSVC didn't support explicit template arguments.

Another option is

 template<class Source, class Target>
 void static_pointer_cast
    ( const smart_ptr<Source> &s, smart_ptr<Target> & t );

Have you tried

#include <boost/pointer_cast.hpp>

// in class

{
    using boost::static_pointer_cast;
    static_pointer_cast<T>( ps );
}

under g++? Does it still fail? This is required to support the case where ps
is a raw pointer.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk