title: Group class template specializations
body: <p><strong>Is there a technique / best style to group class template specializations for certain types ?</strong> </p>
  
  <p>An example : Lets say I have a class template <code>Foo</code> and I need to have it specialized the same for the typeset </p>
  
  <pre><code>A = { Line, Ray }
  </code></pre>
  
  <p>and in another way for the typeset B</p>
  
  <pre><code>B = { Linestring, Curve }
  </code></pre>
  
  <hr>
  
  <p>What I'm doing so far : (the technique is also presented <a href="https://stackoverflow.com/a/12250160/2567683">here</a> for functions) </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  using namespace std;
  
  // 1st group
  struct Line    {};
  struct Ray     {};
  // 2nd group 
  struct Curve      {};
  struct Linestring {};
  
  template&lt;typename T, typename Groupper=void&gt;
  struct Foo
  { enum { val = 0 }; };
  
  // specialization for the 1st group 
  template&lt;typename T&gt;
  struct Foo&lt;T, typename enable_if&lt;
      is_same&lt;T, Line&gt;::value ||
      is_same&lt;T, Ray&gt;::value
  &gt;::type&gt;
  {
      enum { val = 1 };
  };
  
  // specialization for the 2nd group 
  template&lt;typename T&gt;
  struct Foo&lt;T, typename enable_if&lt;
      is_same&lt;T, Curve&gt;::value ||
      is_same&lt;T, Linestring&gt;::value
  &gt;::type&gt;
  {
      enum { val = 2 };
  };
  
  int main() 
  {
      cout &lt;&lt; Foo&lt;Line&gt;::val &lt;&lt; endl;
      cout &lt;&lt; Foo&lt;Curve&gt;::val &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>An extra helper struct <code>enable_for</code> would shorten the code (and allow to write the accepted types directly). Any other suggestions, corrections? Shouldn't this involve less effort?</p>