【发布时间】:2015-05-07 00:30:35
【问题描述】:
我正在尝试为函数模板更改一些宏(我们有很多)。很多时候,我有以下场景:
#include <iostream>
void function_A( void )
{
std::cout << "function A" << std::endl;
}
void function_B( void )
{
std::cout << "function B" << std::endl;
}
#define FOO( _bar ) \
do { \
/* ... do something */ \
function_##_bar(); \
/* ... do something */ \
} while( 0 )
int main()
{
FOO( A );
FOO( B );
}
如何将FOO表示为函数模板并达到相同的结果?
我的想法是这样的:
template < ??? _bar >
void foo()
{
// somehow link function_X and _bar
}
性能是必须的!!
提前致谢。
【问题讨论】:
-
你能把原始代码的完整编译示例放上去吗?
-
“很多时候,我有以下场景” - 代码异味?
标签: c++ templates macros concatenation c-preprocessor