title: template parameters, #define and code duplication
body: <p>I have a lot of code like this:</p>
  
  <pre><code>#define WITH_FEATURE_X
  
  struct A {
  #ifdef WITH_FEATURE_X
    // ... declare some variables Y
  #endif
    void f ();
  };
  
  void A::f () {
    // ... do something
  #ifdef WITH_FEATURE_X
    // ... do something and use Y
  #else
    // ... do something else
  #endif
    // ... do something
  }
  </code></pre>
  
  <p>and I'd like to replace the #defines with template parameters:</p>
  
  <pre><code>template &lt; int WITH_FEATURE_X &gt; // can be 0 or 1
  struct A;
  </code></pre>
  
  <p>But I don't want to duplicate almost the entire code of A::f() for A&lt;0>::f() and A&lt;1>::f() just for the few lines that depend on the parameter. I also don't want to call functions instead of the previous #ifdefs. What is the common solution?</p>