type_traits

最近喜欢用编译器搞些事情,记录一下获取类型名和获取基础类型的方式

type_traits.h

#ifndef __TYPE_TRAITS_H_INCLUDED__
#define __TYPE_TRAITS_H_INCLUDED__


#include 

    typedef char               sint8 ;
    typedef unsigned char      uint8 ;
    typedef short              sint16;
    typedef unsigned short     uint16;
    typedef int                sint32;
    typedef unsigned int       uint32;
    typedef long long          sint64;
    typedef unsigned long long uint64;
    typedef long               slong ;
    typedef unsigned long      ulong ;


    template struct type_name { };

    template<> struct type_name { static const char* value; };
    template<> struct type_name { static const char* value; };

    template<> struct type_name  { static const char* value; };
    template<> struct type_name  { static const char* value; };

    template<> struct type_name { static const char* value; };
    template<> struct type_name { static const char* value; };

    template<> struct type_name { static const char* value; };
    template<> struct type_name { static const char* value; };

    template<> struct type_name { static const char* value; };
    template<> struct type_name { static const char* value; };

    template<> struct type_name { static const char* value; };
    template<> struct type_name { static const char* value; };

    template<> struct type_name> { static const char* value; };
    template<> struct type_name> { static const char* value; };

    template<> struct type_name>  { static const char* value; };
    template<> struct type_name>  { static const char* value; };

    template<> struct type_name> { static const char* value; };
    template<> struct type_name> { static const char* value; };

    template<> struct type_name> { static const char* value; };
    template<> struct type_name> { static const char* value; };

    template<> struct type_name> { static const char* value; };
    template<> struct type_name> { static const char* value; };

    template<> struct type_name> { static const char* value; };
    template<> struct type_name> { static const char* value; };


    template  struct base_type                   { typedef T  result_type;};
    template struct base_type> { typedef eT result_type;};



namespace Private {

    template struct __long_name_str {}; /*complex, signed, byte size*/
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };
    template<> struct __long_name_str { static const char* value; };

} /*namespace ::Private*/


#endif // __TYPE_TRAITS_H_INCLUDED__

type_traits.cpp


#include "type_traits.h"
namespace Private {

    /*template struct __long_name_str {};*/ /*complex, signed, byte size*/
    const char* __long_name_str::value = "slong 16";
    const char* __long_name_str::value = "slong 32";
    const char* __long_name_str::value = "slong 64";

    const char* __long_name_str::value = "complex slong 16";
    const char* __long_name_str::value = "complex slong 32";
    const char* __long_name_str::value = "complex slong 64";

    const char* __long_name_str::value = "ulong 16";
    const char* __long_name_str::value = "ulong 32";
    const char* __long_name_str::value = "ulong 64";

    const char* __long_name_str::value = "complex ulong 16";
    const char* __long_name_str::value = "complex ulong 32";
    const char* __long_name_str::value = "complex ulong 64";

} /*namespace ::Private*/

    
    const char* type_name::value  = "float";
    const char* type_name::value = "double";

    const char* type_name::value  = "sint8";
    const char* type_name::value  = "uint8";

    const char* type_name::value = "sint16";
    const char* type_name::value = "uint16";

    const char* type_name::value = "sint32";
    const char* type_name::value = "uint32";

    const char* type_name::value = "sint64";
    const char* type_name::value = "uint64";

    const char* type_name::value  = Private::__long_name_str::value;
    const char* type_name::value  = Private::__long_name_str::value;

    const char* type_name>::value  = "complex float";
    const char* type_name>::value = "complex double";

    const char* type_name>::value  = "complex sint8";
    const char* type_name>::value  = "complex uint8";

    const char* type_name>::value = "complex sint16";
    const char* type_name>::value = "complex uint16";

    const char* type_name>::value = "complex sint32";
    const char* type_name>::value = "complex uint32";

    const char* type_name>::value = "complex sint64";
    const char* type_name>::value = "complex uint64";

    const char* type_name>::value  = Private::__long_name_str::value;
    const char* type_name>::value  = Private::__long_name_str::value;


 

你可能感兴趣的:(C++)