How do I implement no-op macro (or template) in C++?
Solution 1:
While leaving it blank is the obvious option, I'd go with
#define conditional_noop(x) do {} while(0)
This trick is obviously no-op, but forces you to write a semicolon after conditional_noop(123)
.
Solution 2:
As mentioned before - nothing.
Also, there is a misprint in your code.
it should be #else not #elif. if it is #elif it is to be followed by the new condition
#include <iostream>
#ifdef NOOP
#define conditional_noop(x) do {} while(0)
#else
#define conditional_noop(x) std::cout << (x)
#endif
Have fun coding! EDIT: added the [do] construct for robustness as suggested in another answer.