在编译期,获得函数参数个数
来源:互联网 发布:linux关闭nagle算法 编辑:程序博客网 时间:2024/06/15 12:15
#if _MSC_VER >= 1900
#define _CONST_EXPR constexpr
#define _NO_EXCEPT noexcept
#else
#define _CONST_EXPR inline
#define _NO_EXCEPT throw()
#endif
#define MYLIB_START namespace myLib{
#define MYLIB_END }
MYLIB_START
template<typename _FuncTy>
struct _get;
template<typename _RetTy, typename... paramsTy>
struct _get<_RetTy(*)(paramsTy...)>
{
static size_t const value = sizeof...(paramsTy);
};
template<typename _FuncTy>
_CONST_EXPR size_t getParamNum(_FuncTy) noexcept
{
return _get<_FuncTy>::value;
}
MYLIB_END
#undef MYLIB_START
#undef MYLIB_END
#define _NO_EXCEPT noexcept
#else
#define _CONST_EXPR inline
#define _NO_EXCEPT throw()
#endif
#define MYLIB_START namespace myLib{
#define MYLIB_END }
MYLIB_START
template<typename _FuncTy>
struct _get;
template<typename _RetTy, typename... paramsTy>
struct _get<_RetTy(*)(paramsTy...)>
{
static size_t const value = sizeof...(paramsTy);
};
template<typename _FuncTy>
_CONST_EXPR size_t getParamNum(_FuncTy) noexcept
{
return _get<_FuncTy>::value;
}
MYLIB_END
#undef MYLIB_START
#undef MYLIB_END
int testFunc0()
{
return 0;
}
{
return 0;
}
int testFunc1(int i, int k)
{
return 0;
}
{
return 0;
}
int testFunc2(int i, int k, int c)
{
return 0;
}
{
return 0;
}
void main()
{
size_t i0 = myLib::getParamNum(testFunc0);
size_t i1 = myLib::getParamNum(testFunc1);
size_t i2 = myLib::getParamNum(testFunc2);
}
{
size_t i0 = myLib::getParamNum(testFunc0);
size_t i1 = myLib::getParamNum(testFunc1);
size_t i2 = myLib::getParamNum(testFunc2);
}
阅读全文
0 0
- 在编译期,获得函数参数个数
- C/C++ 使用宏在编译期计算可变参数个数
- CDECL 调用函数内。获得参数个数。
- 一种在编译期保证模板类参数T必须实现某函数的方法
- 编译期强制函数参数为字符串常量
- 缺省参数是在编译期决定的
- 编译期assert函数
- 函数参数个数
- javascript 函数参数 个数
- JavaScript函数参数个数
- JavaScript函数参数个数
- 参数个数可变函数
- 获得函数参数名
- 在VB中实现向函数传递不定个数参数
- 在VB中实现向函数传递不定个数参数
- 编译期成员函数检查
- 参数个数不确定的函数
- 函数参数的理想个数
- 博客园 首页 新随笔 联系 订阅 管理 Ubuntu 16.04搭建LAMP开发环境 1. 配置网络环境 略 2. 设置ROOT密码 sud
- echarts2-网络动态攻击(带涟漪效果)
- 经验分享 | 【PDF下载】大数据峰会之MaxCompute数据上云与生态
- Android使用共享元素实现转场动画 错误:Unable to create layer for LinearLayout
- [转] 如何把书上的字弄到电脑上
- 在编译期,获得函数参数个数
- YARN ResourceManager调度器的分析
- 网络广告投放基础,广告
- JSP的内置对象
- RHEL linux7.3 安装Apache服务
- Oracle快速入门(2)——Oracle安装教程
- CSS学习总结
- 六、操作系统之文件管理
- Is Subsequence问题及解法