wetwoo的小窝
wetwoo的小窝

导航

<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
统计
  • 随笔 - 22
  • 文章 - 4
  • 评论 - 14
  • 引用 - 0

留言簿(1)

随笔档案

文章档案

相册

搜索

最新评论

阅读排行榜

评论排行榜

/* 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)  编辑 收藏
Comments
标题  
姓名  
主页
验证码 *
内容   
  登录  使用高级评论  Top
[使用Ctrl+Enter键可以直接提交]