Templates are the Gateway Drug for Macros

If you’ve read a half-inch-thick C++ book in the last few years, you’ve probably heard that you should never use macros. Instead you should use inline functions and templates (with a few exceptions, such as use of __FILE__ and __LINE__.)

Well, I’m here to say that there is nothing in C++ which will drive someone to write more macros than templates.

Templates merely whet my appetite for compile-time code-generation, and then almost always fall short. Ultimately, my devotion to the DRY principle is stronger than my allegance to Sutter or Meyers — so I write a macro and get on with my life.


%d bloggers like this: