Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-06-16 14:02:19


> Please ignore the previous code. Kindly consider the following:
>
> template<class T> struct type {};
>
> // static_pointer_cast_impl overload for raw pointers
> template<class T, class U>
> inline T* static_pointer_cast_impl(U *ptr, type<T>)
> {
> return static_cast<T*>(ptr);
> }
>
> // static_pointer_cast ADL dispatcher function
> template<class T, class U>
> inline T static_pointer_cast(U u)
> {
> return static_pointer_cast_impl(u, type<T>()); // ADL kicks in here
> }
>
> // ...
>
> template<class T> class smart_ptr { /* ... */ };
>
> // static_pointer_cast_impl overload for raw smart_ptr
> template<class T, class U>
> inline smart_ptr<T> static_pointer_cast_impl(smart_ptr<U> const& p, type<T>)
> {
> return smart_ptr<T>(p.get());
> }

Seems ok, although "type<T>" could be something like
"cast_to_pointer<T>". Whatever we choose, I think we should add it to
"shared_ptr" and "intrusive_ptr", and define well-known boost ADL
casting functions.

Current "xxx_pointer_cast" is in TR1, so I don't know if we have arrived
late for an standard C++ ADL friendly cast functions. Peter?

Regards,

Ion


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