1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/meta/implicitconversion.h
3 // Purpose: Determine resulting type from implicit conversion
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2010 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_META_IMPLICITCONVERSION_H_
12 #define _WX_META_IMPLICITCONVERSION_H_
15 #include "wx/meta/if.h"
17 // C++ hierarchy of data types is:
19 // Long double (highest)
27 // Types lower in the hierarchy are converted into ones higher up if both are
28 // involved e.g. in arithmetic expressions.
36 // consider unknown types (e.g. objects, pointers) to be of highest
37 // level, always convert to them if they occur
38 enum { level
= 9999 };
41 #define WX_TYPE_HIERARCHY_LEVEL(level_num, type) \
42 template<> struct TypeHierarchy<type> \
44 enum { level = level_num }; \
47 WX_TYPE_HIERARCHY_LEVEL( 1, char);
48 WX_TYPE_HIERARCHY_LEVEL( 2, unsigned char);
49 WX_TYPE_HIERARCHY_LEVEL( 3, short);
50 WX_TYPE_HIERARCHY_LEVEL( 4, unsigned short);
51 WX_TYPE_HIERARCHY_LEVEL( 5, int);
52 WX_TYPE_HIERARCHY_LEVEL( 6, unsigned int);
53 WX_TYPE_HIERARCHY_LEVEL( 7, long);
54 WX_TYPE_HIERARCHY_LEVEL( 8, unsigned long);
56 WX_TYPE_HIERARCHY_LEVEL( 9, wxLongLong_t
);
57 WX_TYPE_HIERARCHY_LEVEL(10, wxULongLong_t
);
59 WX_TYPE_HIERARCHY_LEVEL(11, float);
60 WX_TYPE_HIERARCHY_LEVEL(12, double);
61 WX_TYPE_HIERARCHY_LEVEL(13, long double);
63 #if wxWCHAR_T_IS_REAL_TYPE
64 #if SIZEOF_WCHAR_T == SIZEOF_SHORT
65 template<> struct TypeHierarchy
<wchar_t> : public TypeHierarchy
<short> {};
66 #elif SIZEOF_WCHAR_T == SIZEOF_INT
67 template<> struct TypeHierarchy
<wchar_t> : public TypeHierarchy
<int> {};
68 #elif SIZEOF_WCHAR_T == SIZEOF_LONG
69 template<> struct TypeHierarchy
<wchar_t> : public TypeHierarchy
<long> {};
71 #error "weird wchar_t size, please update this code"
75 #undef WX_TYPE_HIERARCHY_LEVEL
77 } // namespace wxPrivate
79 // Helper to determine resulting type of implicit conversion in
80 // an expression with two arithmetic types.
81 template<typename T1
, typename T2
>
82 struct wxImplicitConversionType
86 // if T2 is "higher" type, convert to it
87 (int)wxPrivate::TypeHierarchy
<T1
>::level
< (int)wxPrivate::TypeHierarchy
<T2
>::level
,
96 template<typename T1
, typename T2
, typename T3
>
97 struct wxImplicitConversionType3
: public wxImplicitConversionType
<
99 typename wxImplicitConversionType
<T2
,T3
>::value
>
103 #endif // _WX_META_IMPLICITCONVERSION_H_