C++中通过类型萃取来实现对象类型的识别。
类型萃取的实际用例:1.SeqList 2.统一内存管理 3.STL
POD:plain old data平凡类型--基本类型,值C++中与C兼容的类型,可以按照C的方式处理
POD类型萃取如下:
#pragma once
struct _TrueType
{};
struct _FlaseType
{};
template <class T>
struct TypeTraits
{
typedef _FlaseType IsPodType;
};
template <>
struct TypeTraits<int>
{
typedef _TrueType IsPodType;
};
template <>
struct TypeTraits<char>
{
typedef _TrueType IsPodType;
};
template <>
struct TypeTraits<double>
{
typedef _TrueType IsPodType;
};
template<>
struct TypeTraits<float>
{
typedef _TrueType IsPodType;
};
template <class T>
struct TypeTraits<T*>
{
typedef _TrueType IsPodType;
};
template <class T>
T* _Copy(T* dst, T* src, size_t n, _FlaseType)
{
for (size_t i = 0; i < n; i++)
{
dst