# TmplArgs **Repository Path**: lvan100/TmplArgs ## Basic Information - **Project Name**: TmplArgs - **Description**: TmplArgs,使用模板技术分析函数参数,从而在编译期得到更多信息和条件。 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 2 - **Created**: 2015-04-07 - **Last Updated**: 2025-07-21 ## Categories & Tags **Categories**: ci **Tags**: None ## README # TmplArgs 我们可以通过函数重载为同名函数实现不同参数个数的版本,如: int max(int a, int b) { return a>b?a:b; } int max(int a, int b, int c) { return max(a,b)>max(b,c)?max(a,b):max(b,c); } 我们还可以通过使用函数模板来扩展函数对参数类型的定制,如: template void debug(_T a, std::string b) { cout< void debug(_T a, _T1 b, std::string c) { cout< struct Debug { _T _a; Debug(_T a) : _a(a) {} void debug(std::string s) { cout<<_a< struct Debug { _T _a; _T1 _b; Debug(_T a, _T1 b) : _a(a), _b(b) {} void debug(std::string s) { cout<<_a<<_b< 首先,我们需要实现类模板的宏定义式,如 DebugBase.h。
然后,我们需要实现类模板的通用形式,如 Debug.h。
最后,我们还需要将参数规则写成函数指针的形式。
下面这段代码就是使用 TmplArgs 后对上面的 Debug 模板的改写: Debug a; a.debug(3,"0"); Debug b; b.debug(3, "4", "0");