promote_type.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup promote_type
00018 //! @{
00019 
00020 
00021 
00022 template<typename T1, typename T2>
00023 struct promote_type
00024   {
00025   inline static void check()
00026     {
00027     arma_static_assert<false> ERROR___UNSUPPORTED_MIXTURE_OF_TYPES;
00028     ERROR___UNSUPPORTED_MIXTURE_OF_TYPES = ERROR___UNSUPPORTED_MIXTURE_OF_TYPES;
00029     }
00030   
00031   typedef T1 result;
00032   };
00033 
00034 
00035 
00036 struct promote_type_ok
00037   {
00038   arma_inline static void check() {}
00039   };
00040 
00041 
00042 template<typename T> struct promote_type<T,               T> : public promote_type_ok { typedef T               result; };
00043 template<typename T> struct promote_type<std::complex<T>, T> : public promote_type_ok { typedef std::complex<T> result; };
00044 
00045 template<> struct promote_type<std::complex<double>, std::complex<float> > : public promote_type_ok { typedef std::complex<double> result; };
00046 template<> struct promote_type<std::complex<double>, float>                : public promote_type_ok { typedef std::complex<double> result; };
00047 template<> struct promote_type<std::complex<float>,  double>               : public promote_type_ok { typedef std::complex<double> result; };
00048 
00049 template<typename T> struct promote_type<std::complex<T>, s32> : public promote_type_ok { typedef std::complex<T> result; };
00050 template<typename T> struct promote_type<std::complex<T>, u32> : public promote_type_ok { typedef std::complex<T> result; };
00051 template<typename T> struct promote_type<std::complex<T>, s16> : public promote_type_ok { typedef std::complex<T> result; };
00052 template<typename T> struct promote_type<std::complex<T>, u16> : public promote_type_ok { typedef std::complex<T> result; };
00053 template<typename T> struct promote_type<std::complex<T>, s8>  : public promote_type_ok { typedef std::complex<T> result; };
00054 template<typename T> struct promote_type<std::complex<T>, u8>  : public promote_type_ok { typedef std::complex<T> result; };
00055 
00056 
00057 template<> struct promote_type<double, float> : public promote_type_ok { typedef double result; };
00058 template<> struct promote_type<double, s32  > : public promote_type_ok { typedef double result; };
00059 template<> struct promote_type<double, u32  > : public promote_type_ok { typedef double result; };
00060 template<> struct promote_type<double, s16  > : public promote_type_ok { typedef double result; };
00061 template<> struct promote_type<double, u16  > : public promote_type_ok { typedef double result; };
00062 template<> struct promote_type<double, s8   > : public promote_type_ok { typedef double result; };
00063 template<> struct promote_type<double, u8   > : public promote_type_ok { typedef double result; };
00064 
00065 template<> struct promote_type<float, s32> : public promote_type_ok { typedef float result; };
00066 template<> struct promote_type<float, u32> : public promote_type_ok { typedef float result; };
00067 template<> struct promote_type<float, s16> : public promote_type_ok { typedef float result; };
00068 template<> struct promote_type<float, u16> : public promote_type_ok { typedef float result; };
00069 template<> struct promote_type<float, s8 > : public promote_type_ok { typedef float result; };
00070 template<> struct promote_type<float, u8 > : public promote_type_ok { typedef float result; };
00071 
00072 template<> struct promote_type<s32, u32> : public promote_type_ok { typedef s32 result; };  // float ?  
00073 template<> struct promote_type<s32, s16> : public promote_type_ok { typedef s32 result; };
00074 template<> struct promote_type<s32, u16> : public promote_type_ok { typedef s32 result; };
00075 template<> struct promote_type<s32, s8 > : public promote_type_ok { typedef s32 result; };
00076 template<> struct promote_type<s32, u8 > : public promote_type_ok { typedef s32 result; };
00077 
00078 template<> struct promote_type<u32, s16> : public promote_type_ok { typedef s32 result; };  // float ?
00079 template<> struct promote_type<u32, u16> : public promote_type_ok { typedef u32 result; };
00080 template<> struct promote_type<u32, s8 > : public promote_type_ok { typedef s32 result; };  // float ?
00081 template<> struct promote_type<u32, u8 > : public promote_type_ok { typedef u32 result; };
00082 
00083 template<> struct promote_type<s16, u16> : public promote_type_ok { typedef s16 result; };  // s32 ?
00084 template<> struct promote_type<s16, s8 > : public promote_type_ok { typedef s16 result; };
00085 template<> struct promote_type<s16, u8 > : public promote_type_ok { typedef s16 result; };
00086 
00087 template<> struct promote_type<u16, s8> : public promote_type_ok { typedef s16 result; };  // s32 ?
00088 template<> struct promote_type<u16, u8> : public promote_type_ok { typedef u16 result; };
00089 
00090 template<> struct promote_type<s8, u8> : public promote_type_ok { typedef s8 result; };  // s16 ?
00091 
00092 
00093 
00094 
00095 //
00096 // mirrored versions
00097 
00098 template<typename T> struct promote_type<T, std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00099 
00100 template<> struct promote_type<std::complex<float>, std::complex<double> > : public promote_type_ok { typedef std::complex<double> result; };
00101 template<> struct promote_type<float,               std::complex<double> > : public promote_type_ok { typedef std::complex<double> result; };
00102 template<> struct promote_type<double,              std::complex<float>  > : public promote_type_ok { typedef std::complex<double> result; };
00103 
00104 template<typename T> struct promote_type<s32, std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00105 template<typename T> struct promote_type<u32, std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00106 template<typename T> struct promote_type<s16, std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00107 template<typename T> struct promote_type<u16, std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00108 template<typename T> struct promote_type<s8,  std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00109 template<typename T> struct promote_type<u8,  std::complex<T> > : public promote_type_ok { typedef std::complex<T> result; };
00110 
00111 
00112 template<> struct promote_type<float, double> : public promote_type_ok { typedef double result; };
00113 template<> struct promote_type<s32  , double> : public promote_type_ok { typedef double result; };
00114 template<> struct promote_type<u32  , double> : public promote_type_ok { typedef double result; };
00115 template<> struct promote_type<s16  , double> : public promote_type_ok { typedef double result; };
00116 template<> struct promote_type<u16  , double> : public promote_type_ok { typedef double result; };
00117 template<> struct promote_type<s8   , double> : public promote_type_ok { typedef double result; };
00118 template<> struct promote_type<u8   , double> : public promote_type_ok { typedef double result; };
00119 
00120 template<> struct promote_type<s32, float> : public promote_type_ok { typedef float result; };
00121 template<> struct promote_type<u32, float> : public promote_type_ok { typedef float result; };
00122 template<> struct promote_type<s16, float> : public promote_type_ok { typedef float result; };
00123 template<> struct promote_type<u16, float> : public promote_type_ok { typedef float result; };
00124 template<> struct promote_type<s8 , float> : public promote_type_ok { typedef float result; };
00125 template<> struct promote_type<u8 , float> : public promote_type_ok { typedef float result; };
00126 
00127 template<> struct promote_type<u32, s32> : public promote_type_ok { typedef s32 result; };  // float ?  
00128 template<> struct promote_type<s16, s32> : public promote_type_ok { typedef s32 result; };
00129 template<> struct promote_type<u16, s32> : public promote_type_ok { typedef s32 result; };
00130 template<> struct promote_type<s8 , s32> : public promote_type_ok { typedef s32 result; };
00131 template<> struct promote_type<u8 , s32> : public promote_type_ok { typedef s32 result; };
00132 
00133 template<> struct promote_type<s16, u32> : public promote_type_ok { typedef s32 result; };  // float ?
00134 template<> struct promote_type<u16, u32> : public promote_type_ok { typedef u32 result; };
00135 template<> struct promote_type<s8 , u32> : public promote_type_ok { typedef s32 result; };  // float ?
00136 template<> struct promote_type<u8 , u32> : public promote_type_ok { typedef u32 result; };
00137 
00138 template<> struct promote_type<u16, s16> : public promote_type_ok { typedef s16 result; };  // s32 ?
00139 template<> struct promote_type<s8 , s16> : public promote_type_ok { typedef s16 result; };
00140 template<> struct promote_type<u8 , s16> : public promote_type_ok { typedef s16 result; };
00141 
00142 template<> struct promote_type<s8, u16> : public promote_type_ok { typedef s16 result; };  // s32 ?
00143 template<> struct promote_type<u8, u16> : public promote_type_ok { typedef u16 result; };
00144 
00145 template<> struct promote_type<u8, s8> : public promote_type_ok { typedef s8 result; };  // s16 ?
00146 
00147 
00148 
00149 template<typename T1, typename T2>
00150 struct eT_promoter
00151   {
00152   typedef typename promote_type<typename T1::elem_type, typename T2::elem_type>::result eT;
00153   };
00154 
00155 
00156 
00157 //! @}