OiO.lk Blog C++ Macro that expands to value or empty, based on boolean argument
C++

Macro that expands to value or empty, based on boolean argument


I’m generating some compile-time code. I need to append a suffix to a generated function name, based on a macro boolean. The suffix is either present or empty. How to do that?

#define FUNC_NAME(name, hasSuffix) name ## MAYBE_SHOW_SUFFIX(hasSuffix)

FUNC_NAME(foo, true);  // would generate: foo_
FUNC_NAME(foo, false); // would generate: foo



You need to sign in to view this answers

Exit mobile version