title: macro which defines new macros with an added prefix
body: <p>We have a profiling framework which can be enabled and disabled at compile time.</p>
  
  <p>All the various calls to the framework are done through macros, eg:</p>
  
  <pre><code>PROFILE_START(msg)
  PROFILE_END(msg)
  </code></pre>
  
  <p>The macros then resolve to the actual profiler call when profiling is enabled, and to nothing when disabled</p>
  
  <pre><code>#ifdef PROFILING_ENABLED
  #    define PROFILE_START(msg) currentProfiler().start(msg)
  #    define PROFILE_END(msg)   currentProfiler().end(msg)
  #else
  #    define PROFILE_START(msg)
  #    define PROFILE_END(msg)   
  #endif
  </code></pre>
  
  <p>We have various different components in our framework, and I want to enable profiling in each component.</p>
  
  <p>I'd like to be able to selectively enable profiling in each component.</p>
  
  <p>My idea is to prefix all the profiler macros with the component's name, eg:</p>
  
  <pre><code>FOO_PROFILE_START(msg)
  FOO_PROFILE_END(msg)
  
  BAR_PROFILE_START(msg)
  BAR_PROFILE_END(msg)
  </code></pre>
  
  <p>I <em>could</em> manually create  </p>
  
  <pre><code>#ifdef ENABLE_FOO_PROFILING
  #    define FOO_PROFILE_START(msg) PROFILE_START(msg)
  #    define FOO_PROFILE_END(msg) PROFILE_END(msg)
  #else
  #    define FOO_PROFILE_START(msg) 
  #    define FOO_PROFILE_END(msg) 
  #endif
  
  #ifdef ENABLE_BAR_PROFILING
  #    define BAR_PROFILE_START(msg) PROFILE_START(msg)
  #    define BAR_PROFILE_END(msg) PROFILE_END(msg)
  #else
  #    define BAR_PROFILE_START(msg) 
  #    define BAR_PROFILE_END(msg) 
  #endif
  </code></pre>
  
  <p>However, this is both tedious and error-prone.</p>
  
  <p>Any time a new feature is added to the profiling framework I would have to find all my component specific macros and add a new macro to each of them.</p>
  
  <p>What I'm looking for is a way to automatically generate the component-prefixed macros.</p>
  
  <pre><code>#ifdef ENABLE_FOO_PROFILING
      ADD_PREFIX_TO_ENABLED_PROFILING_MACROS(FOO)
  #else
      ADD_PREFIX_TO_DISABLED_PROFILING_MACROS(FOO)
  #endif
  </code></pre>
  
  <p>The net result of the above would be to create all the <code>FOO_PROFILE_XXX</code> macros I would have done manually.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>Is such a helper macro possible?</li>
  <li>Is there a better way of achieving what I'm looking for?</li>
  </ul>
  
  <p>I'm happy to use BOOST_PP if necessary.</p>
  
  <hr>
  
  <p>Before posting this question I tried figuring this out myself, and the code I came up with follows, which may serve to show the road I was going down</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define PROFILE_START(msg) printf("start(%s)\n", msg);
  #define PROFILE_END(msg)   printf("end(%s)\n", msg);
  
  #define ENABLE(prefix) \
      #define prefix ## _PROFILE_START PROFILE_START \
      #define prefix ## _PROFILE_END   PROFILE_END
  
  #define DISABLE(prefix) \
      #define prefix ## _PROFILE_START \
      #define prefix ## _PROFILE_END
  
  #define ENABLE_FOO
  
  #ifdef ENABLE_FOO
      ENABLE(FOO)
  #else
      DISABLE(FOO)
  #endif
  
  #ifdef ENABLE_BAR
      ENABLE(BAR)
  #else
      DISABLE(BAR)
  #endif
  
  
  int main()
  {
      FOO_PROFILE_START("foo");
      FOO_PROFILE_END("foo");
  
      BAR_PROFILE_START("bar");
      BAR_PROFILE_END("bar");
  
      return 0;
  }
  </code></pre>