Initially I thought I needed this, but I eventually avoided it. However, my curiosity (and appetite for knowledge, hum) make me ask:
Can a preprocessor macro, for instance in
#include "MyClass.h"
INSTANTIATE_FOO_TEMPLATE_CLASS(MyClass)
expand to another include, like in
#include "MyClass.h"
#include "FooTemplate.h"
template class FooTemplate<MyClass>;
?
I believe that cannot be done, this is because the pre-processor is single pass. So it cannot emit other preprocessor directives.
Specifically, from the C99 Standard (6.10.3.4 paragraph 3):
3 The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one, ...
Interestingly enough, This is why the unary _Pragma
operator was added to c99. Because #pragma
could not be emited by macros, but _Pragma
can.