预处理程序和模板参数或代码的条件编译 [英] Preprocessor and template arguments or conditional compilation of piece of code
本文介绍了预处理程序和模板参数或代码的条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在预处理器条件下编译模板函数?像这样(但不起作用):
How I can compile template function with pre-processor condition? Like that (but it is not working):
template <bool var>
void f()
{
#if (var == true)
// ...
#endif
}
推荐答案
您不能。顾名思义,预处理器在编译器之前处理源文件。因此,它不知道您的模板参数的值。
You can't. The preprocessor, as this names indicates, processes the source file before the compiler. It has therefore no knowledge of the values of your template arguments.
这篇关于预处理程序和模板参数或代码的条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文