How I can compile template function with pre-processor condition? Like that (but it is not working):
template
void f()
{
#if (var == tru
If you need to generate different code paths with template parameter, you can just simply use if
or other C++ statement:
template
void f()
{
if (var == true) {
// ...
}
}
Compiler can optimize it and generate code that doesn't contain such branches.
A little drawback is that some compiler (e.g. Msvc) will generate warnings for conditions which is always constant.