title: Specializing function template for templated derived class
body: <p>I essentially have a mock version of <code>std::integral_constant</code> that includes a variable and I want to specialize a function template for these classes derived from <code>Base&lt;T&gt;</code>, like this:</p>
  
  <pre><code>template&lt;class T&gt; struct Base{
    typedef T type;
    T t;
  };
  
  template&lt;class T&gt; struct A : Base&lt;T&gt;{
    static constexpr T value = 1;
  };
  template&lt;class T&gt; struct B : Base&lt;T&gt;{
    static constexpr T value = 2;
  };
  
  struct Unrelated{};
  
  // etc.
  
  template&lt;class T&gt; void foo(T t){
    //I would like to specialize foo for A and B and have a version for other types
  }
  
  
  int main(){
    foo(A&lt;float&gt;());//do something special based on value fields of A and B
    foo(B&lt;float&gt;());
    foo(Unrelated()); //do some default behavior
  }
  </code></pre>
  
  <p>Here are the main issues:</p>
  
  <ul>
  <li>I cannot include <code>value</code> as a template as I am expecting <code>T = double</code>, <code>float</code>, or some other non-integral types (otherwise I'd just extend <code>std::integral_constant</code>)</li>
  <li>I can't cleanly use <code>std::is_base</code> as I would have to do <code>std::is_base&lt;Base&lt;T::type&gt;,T&gt;</code> </li>
  <li>Doing <code>foo(Base&lt;T&gt;&amp;)</code> wouldn't allow me to see <code>value</code> and I don't want to have to resort to a virtual <code>value()</code> function (or reflection).</li>
  <li>And obviously I would like to avoid specializing foo for every derived class.</li>
  </ul>
  
  <p>I think the answer lies in using <code>is_base</code> but I haven't been able to get it to work no matter how I tried to use it. Is there a much simpler way I am missing?</p>