title: Compiler Error C2766 : "explicit specialization; 'specialization' has already been defined" when using boost::disable_if
body: <p>I'm trying to build a template class <code>Fod</code> </p>
  
  <pre><code>template&lt;typename S0 = aux::EmptyType, typename S1 = aux::EmptyType, typename S2 = aux::EmptyType, typename S3 = aux::EmptyType, typename S4 = aux::EmptyType, typename S5 = aux::EmptyType, typename S6 = aux::EmptyType, typename S7 = aux::EmptyType, typename S8 = aux::EmptyType, typename S9 = aux::EmptyType&gt;
  class Fod { ... };
  </code></pre>
  
  <p>which will contain an inner class At with a <code>static const int value</code> indicating the index of the template argument (0 for S0, 1 for S1 and so on). Shortly, it should satisfy the condition:</p>
  
  <pre><code>struct Type0 {}; struct Type1 {};
  BOOST_STATIC_ASSERT( (Fod&lt;Type0&gt;::At&lt;Type0&gt;::value == 0) );
  BOOST_STATIC_ASSERT( (Fod&lt;Type0, Type1&gt;::At&lt;Type0&gt;::value == 0) );
  BOOST_STATIC_ASSERT( (Fod&lt;Type0, Type1&gt;::At&lt;Type1&gt;::value == 1) );
  </code></pre>
  
  <p>I've tried using <code>boost::disable_if</code> as follows:</p>
  
  <pre><code>template&lt;class T, class Enable = void&gt;
  class At; // undefined
  
  template&lt;&gt;
  struct At&lt;S0, typename boost::disable_if&lt;boost::is_same&lt;S0, aux::EmptyType&gt; &gt;::type &gt; {
      static const int value = 0;
  };
  
  template&lt;&gt;
  struct At&lt;S1, typename boost::disable_if&lt;boost::is_same&lt;S1, aux::EmptyType&gt; &gt;::type &gt; {
      static const int value = 1;
  };
  
  template&lt;&gt;
  struct At&lt;S2, typename boost::disable_if&lt;boost::is_same&lt;S2, aux::EmptyType&gt; &gt;::type &gt; {
      static const int value = 2;
  };
  
  template&lt;&gt;
  struct At&lt;S3, typename boost::disable_if&lt;boost::is_same&lt;S3, aux::EmptyType&gt; &gt;::type &gt; {
      static const int value = 3;
  };
  
  // and so on for S4...S9
  </code></pre>
  
  <p>but it results in error when I define specialization for S3 and both S2,S3 are of the same type <code>aux::EmptyType</code> (or: I define specialization for S2 and both S1,S2 are of the same type).</p>
  
  <pre><code>4&gt;C:\phd\cpp\src\boost/dst/fod.hpp(144): error C2766: explicit specialization ; 'boost::dst::fod&lt;S0&gt;::At&lt;boost::dst::aux::EmptyType,boost::mpl::s_item&lt;T,Base&gt;&gt;' has already been defined
  4&gt;          with
  4&gt;          [
  4&gt;              S0=Type0
  4&gt;          ]
  4&gt;          and
  4&gt;          [
  4&gt;              T=Type0,
  4&gt;              Base=boost::mpl::set0&lt;&gt;::item_
  4&gt;          ]
  </code></pre>
  
  <p>Any ideas how to solve the problem?
  And if I wanted a method <code>size_t at&lt;S0&gt;()</code> to give 0, <code>size_t at&lt;S1&gt;()</code> to give 1...?</p>
  
  <p>Please ask if you need more information.</p>