00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_METAL_CONVERTS_TO_HH
00027 # define MLN_METAL_CONVERTS_TO_HH
00028 
00033 
00034 # include <mln/metal/is_a.hh>
00035 # include <mln/metal/const.hh>
00036 # include <mln/core/def/coord.hh>
00037 
00038 
00039 # define mlc_converts_to(T, U) mln::metal::converts_to< T, U >
00040 
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   
00047   namespace value {
00048     template <unsigned n> struct int_u;
00049     template <unsigned n> struct int_s;
00050   }
00051 
00052 
00053   namespace metal
00054   {
00055 
00056     namespace internal
00057     {
00058 
00059       struct eat 
00060       {
00061         template <typename T> eat(const volatile T&);
00062         template <typename T> eat(T&);
00063       };
00064 
00065       template <typename T, typename U>
00066       struct helper_converts_to_
00067       {
00068         static yes_ selector(U, int);
00069         static no_  selector(eat, ...);
00070       };
00071 
00072     } 
00073 
00074 
00075 
00077     template <typename T, typename U>
00078     struct converts_to : bool_<( sizeof(internal::helper_converts_to_<T, U>
00079                                         ::selector(*internal::make_<mlc_const(T)>::ptr(),
00080                                                    0) )
00081                                  ==
00082                                  sizeof(internal::yes_) )>
00083     {};
00084 
00085 
00086     template <typename T, typename U>
00087     struct converts_to<T*, U*> : converts_to<T, U>
00088     {};
00089 
00090     template <typename T, typename U>
00091     struct converts_to<T**, U**> : false_
00092     {};
00093 
00094 
00095 
00096     
00097 
00098     template <> struct converts_to< float, int        > : true_ {};
00099     template <> struct converts_to< float, def::coord > : true_ {};
00100     template <unsigned n> struct converts_to< float, value::int_u<n> > : true_ {};
00101     template <unsigned n> struct converts_to< float, value::int_s<n> > : true_ {};
00102 
00103     template <> struct converts_to< double, int        > : true_ {};
00104     template <> struct converts_to< double, def::coord > : true_ {};
00105     template <unsigned n> struct converts_to< double, value::int_u<n> > : true_ {};
00106     template <unsigned n> struct converts_to< double, value::int_s<n> > : true_ {};
00107 
00108     
00109 
00110   } 
00111 
00112 
00113 
00114 } 
00115 
00116 
00117 #endif // ! MLN_METAL_CONVERTS_TO_HH