下面是第二种写法,这种写法,把内置类型的判断提出来,可以方便其它地方使用:

template<bool A,typename B,typename C>
struct _if{};

template<typename B,typename C>
struct _if<true,B,C>{ typedef B Type; };

template<typename B,typename C>
struct _if<false,B,C>{ typedef C Type; };

template<typename T,size_t N>
inline size_t ARRAYSIZE(T (&)[N])
{
&nbsp;&nbsp;&nbsp; return N;
}

template<typename T>
struct IsInnerType { static const bool Value = false; };

template<>
struct IsInnerType<bool> { static const bool Value = true; };
template<>
struct IsInnerType<char> { static const bool Value = true; };
template<>
struct IsInnerType<short> { static const bool Value = true; };
template<>
struct IsInnerType<int> { static const bool Value = true; };
template<>
struct IsInnerType<long long> { static const bool Value = true; };
template<>
struct IsInnerType<unsigned char> { static const bool Value = true; };
template<>
struct IsInnerType<unsigned short> { static const bool Value = true; };
template<>
struct IsInnerType<unsigned int> { static const bool Value = true; };
template<>
struct IsInnerType<unsigned long long> { static const bool Value = true; };

template<typename T,size_t N>
struct ArrayAssignInnerType
{
&nbsp;&nbsp;&nbsp; static inline void Invoke(T (&A)[N], T (&B)[N])
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy(A,B,sizeof(A));
&nbsp;&nbsp;&nbsp; }
};

template<typename T,size_t N>
struct ArrayAssignCustomType
{
&nbsp;&nbsp;&nbsp; static inline void Invoke(T (&A)[N], T (&B)[N])
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(size_t i = 0; i < N; ++i)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A[i] = B[i];
&nbsp;&nbsp;&nbsp; }
};

template<typename T,size_t N>
inline void ArrayAssign(T (&A)[N], T (&B)[N])
{
&nbsp;&nbsp;&nbsp; _if<IsInnerType<T>::Value,ArrayAssignInnerType<T,N>,ArrayAssignCustomType<T,N> >::Type::Invoke(A,B);
}

  经过上面的处理,我们可以不用担心效率问题;同时,写起来也方便很多,而且不会出错。直接按如下写OK了:

ArrayAssign(B,A);

  以上代码在VC和GCC下编译通过。