title: checking if a class inherits from any template instantiation of a template
body: <p>I have written a small utility for testing whether or not a type has inherited some template instantiation of a specific template class, either directly or trough inheriting a class that inherits the template. This is accomplished with a SFINAE check using a template function accepting any template instantiation of the provided template and a fallback overload for the default case.</p>
  
  <pre class="lang-cxx prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  
  template&lt;template&lt;class&gt; class T, class U&gt;
  struct isDerivedFrom
  {
      static constexpr bool value = decltype(isDerivedFrom::test(U()))::value;
  private:
      template&lt;class V&gt;
      static std::true_type test(T&lt;V&gt;);
      static std::false_type test(...);
  };
  
  template&lt;class T&gt;
  struct Base {};
  struct Base_D1 : Base&lt;int&gt; {};
  struct Base_D2 : Base&lt;Base_D2&gt; {};
  struct Base_D1_D1 : Base_D1 {};
  struct NotDerived {};
  
  int main()
  {
      std::cout &lt;&lt; std::boolalpha
          &lt;&lt; "is Base_D1 derived from or a template instantiation of Base: "
          &lt;&lt; isDerivedFrom&lt;Base, Base_D1&gt;::value &lt;&lt; "\n"
          &lt;&lt; "is Base_D2 derived from or a template instantiation of Base: "
          &lt;&lt; isDerivedFrom&lt;Base, Base_D2&gt;::value &lt;&lt; "\n"
          &lt;&lt; "is Base_D1_D1 derived from or a template instantiation of Base: "
          &lt;&lt; isDerivedFrom&lt;Base, Base_D1_D1&gt;::value &lt;&lt; "\n"
          &lt;&lt; "is Base&lt;double&gt; derived from or a template instantiation of Base: "
          &lt;&lt; isDerivedFrom&lt;Base, Base&lt;double&gt;&gt;::value &lt;&lt; "\n"
          &lt;&lt; "is NotDerived derived from or a template instantiation of Base: "
          &lt;&lt; isDerivedFrom&lt;Base, NotDerived&gt;::value &lt;&lt; "\n";
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>is Base_D1 derived from or a template instantiation of Base: true
  is Base_D2 derived from or a template instantiation of Base: true
  is Base_D1_D1 derived from or a template instantiation of Base: true
  is Base&lt;double&gt; derived from or a template instantiation of Base: true
  is NotDerived derived from or a template instantiation of Base: false
  </code></pre>
  
  <p>My problem is that if the type to be tested (template argument T of <code>isDerivedFrom</code>) has or inherits a non-public constructor or inherits the template trough non-public inheritance, it causes a compile error because <code>decltype(T())</code> fails if <code>T::T()</code> is not public:</p>
  
  <pre class="lang-cxx prettyprint-override"><code>struct Base {protected: Base(){}};
  struct Derived : private Base&lt;int&gt; {};
  </code></pre>
  
  <p>Is there any way to make this work for all cases? Are there any unmentioned issues with the code?</p>