title: Use of enable_if to match only classes which have a certain static data member, and that has only specific values
body: <p>I want to specialize a function for a subset of classes which: have a certain static data member variable, and such variable has only certain possible values.</p>
  
  <p>The code below illustrates the intent, but it does not compile unless I comment out the lines related to the <code>B</code> classes in <code>main</code>. This is because <code>code</code> is not a member of the <code>Bx</code> classes, but the <code>enable_if</code> condition is valid if the template argument has a <code>code</code> member variables. How should I modify it?</p>
  
  <p>Unfortunately I work with very old compilers, hence no support for C++11: I compile with the option <code>-std=c++03</code>.</p>
  
  <p>Thanks</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/core/enable_if.hpp&gt;
  #include &lt;boost/mpl/or.hpp&gt;
  #include &lt;boost/mpl/not.hpp&gt;
  #include &lt;boost/mpl/bool.hpp&gt;
  using std::cout;
  using namespace boost;
  using namespace boost::mpl;
  
  template &lt;int N&gt; struct A1 { static const int code = N; };
  template &lt;int N&gt; struct A2 { static const int code = N; };
  // ... other classes with static data member 'code'
  template &lt;int N&gt; struct AN { static const int code = N; };
  
  struct B1{};
  struct B2{};
  // ... other classes potentially passd as argument to the foo function
  struct BN{};
  
  template &lt;typename T&gt;
  struct Condition : or_&lt;bool_&lt;T::code == 1&gt;, bool_&lt;T::code == 2&gt; &gt; {};
  
  
  template &lt;typename T&gt;
  typename enable_if&lt;not_&lt;Condition&lt;T&gt; &gt;, void&gt;::type
     foo(const T&amp; arg) { cout &lt;&lt; "This class does not have a static member code or its value is not 1 or 2\n"; }
  
  template &lt;typename T&gt;
  typename enable_if&lt;Condition&lt;T&gt;, void&gt;::type
     foo(const T&amp; arg) { cout &lt;&lt; "This class has a static member code and its value is " &lt;&lt; T::code &lt;&lt; "\n"; }
  
  int main()
  {
      foo(A1&lt;0&gt;()); // this should match the 1st version of foo
      foo(A2&lt;1&gt;()); // this should match the 2nd version of foo
      foo(AN&lt;2&gt;()); // this should match the 2nd version of foo
      foo(B1());    // this should match the 1st version of foo
      foo(BN());    // this should match the 1st version of foo
  }
  </code></pre>