You cannot do this with a preprocessor. All you can do is delegate the code into a separate template, something like this:
template <bool var> void only_if_true() {} template <> void only_if_true<true>() { your_special_code_here(); } template <bool var> void f() { some_code_always_used(); only_if_true<var>(); some_code_always_used(); }
Of course, if you need information shared between f() and only_if_true() (which is quite likely), you should pass it as parameters. Or make only_if_true class and save the general data in it.
Angew source share