- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
template <typename T> struct convert_primitive_type_to_class
{
typedef
typename std::conditional< std::is_same< T, void >::value, Void,
typename std::conditional< std::is_same< T, int8_t >::value, SByte,
typename std::conditional< std::is_same< T, uint8_t >::value, Byte,
typename std::conditional< std::is_same< T, int16_t >::value, Int16,
typename std::conditional< std::is_same< T, uint16_t >::value, UInt16,
typename std::conditional< std::is_same< T, char16_t >::value, Char,
typename std::conditional< std::is_same< T, int32_t >::value, Int32,
typename std::conditional< std::is_same< T, uint32_t >::value, UInt32,
typename std::conditional< std::is_same< T, int64_t >::value, Int64,
typename std::conditional< std::is_same< T, uint64_t >::value, UInt64,
typename std::conditional< std::is_same< T, float >::value, Single,
typename std::conditional< std::is_same< T, double >::value, Double,
T
>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type type;
};
template <typename T> struct convert_class_to_primitive_type
{
typedef
typename std::conditional< std::is_same< T, Void >::value, void,
typename std::conditional< std::is_same< T, SByte >::value, int8_t,
typename std::conditional< std::is_same< T, Byte >::value, uint8_t,
typename std::conditional< std::is_same< T, Int16 >::value, int16_t,
typename std::conditional< std::is_same< T, UInt16 >::value, uint16_t,
typename std::conditional< std::is_same< T, Char >::value, char16_t,
typename std::conditional< std::is_same< T, Int32 >::value, int32_t,
typename std::conditional< std::is_same< T, UInt32 >::value, uint32_t,
typename std::conditional< std::is_same< T, Int64 >::value, int64_t,
typename std::conditional< std::is_same< T, UInt64 >::value, uint64_t,
typename std::conditional< std::is_same< T, Single >::value, float,
typename std::conditional< std::is_same< T, Double >::value, double,
T
>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type>::type type;
};
мапирование типов в C++ через шаблоны.
пример юза:
convert_primitive_type_to_class<uint16_t >::type - вернет "UInt16" type