/* const int ARRAY_LEN(ar); */
#ifdef __cplusplus
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#define ARRAY_LEN(ar) (SIZEOF(ar) / SIZEOF(0[ar]))
#else
template<int N>
struct bytes_struct_of_ARRAY_LEN
{
char b[N];
};
template<typename T, int N>
bytes_struct_of_ARRAY_LEN<N> get_bytes_struct_of_ARRAY_LEN(T (&) [N]);
#define ARRAY_LEN(x) SIZEOF(get_bytes_struct_of_ARRAY_LEN(x))
#endif
#else
#define ARRAY_LEN(ar) (SIZEOF(ar) / SIZEOF(0[ar]))
#endif
注:
1.0[ar]仅为了避免ar为vector类型时导致编译错误
2.红色部分仅为了推导出常数N,非数组类型将会出错误
posted on 2007-10-12 10:07 wetwoo的小窝 阅读(1202)
评论(0) 编辑 收藏