title: How to create multiple versions of a method in c++?
body: <p>I have the following problem. I have programmed the following method. With the flag it is set, which version is used.</p>
  
  <pre><code>#define version2
  void calc(double &amp;x
   #ifdef version2
     , double &amp;dot_x
   #endif){
     for(int i=0;i&lt;n;i++){
       double data[]=[... expensive computation ...];
       x=[... something depending on data...];
       #ifdef version2
         dot_x=[... something depending on data ...];
       #endif
     }
  }
  </code></pre>
  
  <p>But now, I need both versions at the same time and I don't want to copy it. Because I would have to make changes at the computation of data in both the versions every time.
  Is there any possibility (like makro etc) to have both versions implemented in one place? And without if-decitions, which cost time?</p>
  
  <p>Thanks a lot for answers,</p>
  
  <p>kildschrote</p>