Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-08-07 12:49:11


On Mon, Aug 07, 2000 at 06:37:46AM -0400, John Maddock wrote:

> While messing about with the is_convertible type-traits template it occured
> to me that there is an interesting use for shared_ptr.

Nitpicking: is_convertible is meta-function, not a type-trait.
Type-traits document things. is_convertible examine them.
 
Note also that is_convertible will fail to compile when access
control is violated.
   
> Currently shared_ptr uses an implicit static_cast in it's template member
> functions

[valentin_at_mercure valentin]$ lynx -dump
www.boost.org/libs/smart_ptr/smart_ptr.hpp | grep static_cast
[valentin_at_mercure valentin]$

Smart_ptr does not use static_cast.
   
> namespace detail{
>
> template <bool>
> struct cast_selector
> {
> template <class T, class U>
> static T do_cast(U u, T) { return dynamic_cast<T>(u); }
> };
>
> template<>
> struct cast_selector<true>
> {
> template <class T, class U>
> static T do_cast(U u, T) { return static_cast<T>(u); }
> };
>
> } // detail
>
> template <class T, class U>
> T maybe_cast(U* u, T = 0)
> {
> typedef detail::cast_selector<is_convertible<U*,T>::value> sw;
> return sw::do_cast(u, (T)(0));
> }

Please explain the semantics of maybe_cast. (You don't have the right
to use disjonctions (OR) in your definition, of course.)

BTW, where are do_static_cast, do_dynamic_cast, do_const_cast ?
   

-- 
Valentin Bonnard

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