关于模板的问题(关于loki)
#include "stdafx.h"
//判断型别T是否为Array
template<typename T>
class IsArray
{
template <typename> struct Type2Type2 {};
typedef char (&yes)[1];
typedef char (&no) [2];
template<typename U, size_t N>
static void vc7_need_this_for_is_array(Type2Type2<U(*)[N]>);
template<typename U, size_t N>
static yes is_array1(Type2Type2<U[N]>*);
static no is_array1(...);
template<typename U>
static yes is_array2(Type2Type2<U[]>*);
static no is_array2(...);
public:
enum { //是Array则value为1
value =
sizeof(is_array1((Type2Type2<T>*)0)) == sizeof(yes) ||
sizeof(is_array2((Type2Type2<T>*)0)) == sizeof(yes)
};
};
int _tmain(int argc, _TCHAR* argv[])
{
IsArray<double[]> da;
printf("%d\n",da.value);
printf("%d\n",IsArray<double[]>::value);
IsArray<double[5]> da2;
printf("%d\n",da2.value);
printf("%d\n",IsArray<double[5]>::value);
IsArray<double> d;
printf("%d\n",d.value);
printf("%d\n",IsArray<double>::value);
IsArray< std::vector<int> > v;
printf("%d\n",v.value);
printf("%d\n",IsArray< std::vector<int> >::value);
return 0;
}
谁能解释一下
enum { //是Array则value为1
value =
sizeof(is_array1((Type2Type2<T>*)0)) == sizeof(yes) ||
sizeof(is_array2((Type2Type2<T>*)0)) == sizeof(yes)
};
这一句?