October 22, 2024
Chicago 12, Melborne City, USA
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

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video