title: C++ execute an action for each type in a given list
body: <p>I have been given the charge to refactor old code and have stumbled upon this case: </p>
  
  <pre><code>void myClass::doStuff()
  {
      for( myIterator&lt; Type1 &gt; it( this-&gt;getDatabase() ); it; ++it )
      {
          do1( *it );
          do2( *it );
          do3( *it );
      }
      for( myIterator&lt; Type2 &gt; it( this-&gt;getDatabase() ); it; ++it )
      {
          do1( *it );
          do2( *it );
          do3( *it );
      }
      for( myIterator&lt; Type3 &gt; it( this-&gt;getDatabase() ); it; ++it )
      {
          do1( *it );
          do2( *it );
          do3( *it );
      }
  }
  </code></pre>
  
  <p>It's obviously bad since I copy basically the same code 3 times so I decided to refactor it using templates like this :</p>
  
  <pre><code>template&lt;class _type&gt; void myClass::do123()
  {
      for( myIterator&lt; _type &gt; it( this-&gt;getDatabase() ); it; ++it )
      {
          do1( *it );
          do2( *it );
          do3( *it );
      }
  }
  void myClass::doStuffBetter()
  {
      do123&lt;Type1&gt;();
      do123&lt;Type2&gt;();
      do123&lt;Type3&gt;();
  }
  </code></pre>
  
  <p>Is there other easier/more productive ways to factorize this kind of repetition in code ?</p>
  
  <p>Bonus question : if my types were not static but given in a variadic template how would I do a similar treatment ?</p>