CppCMS
booster/smart_ptr/sp_convertible.h
00001 #ifndef BOOSTER_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED
00002 #define BOOSTER_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED
00003 
00004 
00005 //  detail/sp_convertible.hpp
00006 //
00007 //  Copyright 2008 Peter Dimov
00008 //
00009 //  Distributed under the Boost Software License, Version 1.0.
00010 //  See accompanying file LICENSE_1_0.txt or copy at
00011 //  http://www.boost.org/LICENSE_1_0.txt
00012 
00013 #include <booster/config.h>
00014 
00015 namespace booster
00016 {
00017 
00018 namespace detail
00019 {
00020 
00021 template< class Y, class T > struct sp_convertible
00022 {
00023     typedef char (&yes) [1];
00024     typedef char (&no)  [2];
00025 
00026     static yes f( T* );
00027     static no  f( ... );
00028 
00029     enum _vt { value = sizeof( f( static_cast<Y*>(0) ) ) == sizeof(yes) };
00030 };
00031 
00032 struct sp_empty
00033 {
00034 };
00035 
00036 template< bool > struct sp_enable_if_convertible_impl;
00037 
00038 template<> struct sp_enable_if_convertible_impl<true>
00039 {
00040     typedef sp_empty type;
00041 };
00042 
00043 template<> struct sp_enable_if_convertible_impl<false>
00044 {
00045 };
00046 
00047 template< class Y, class T > struct sp_enable_if_convertible: public sp_enable_if_convertible_impl< sp_convertible< Y, T >::value >
00048 {
00049 };
00050 
00051 } // namespace detail
00052 
00053 } // namespace boost
00054 
00055 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_CONVERTIBLE_HPP_INCLUDED