title: c++ metaprogram, member type test?
body: <p>I try to write a template meta function to test &quot;is a type <code>T</code> has a member type, named <code>type</code>&quot;.</p>
  <p>here is the code:</p>
  <pre class="lang-cpp prettyprint-override"><code>
  #include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  
  template &lt;typename T, typename E = void&gt;
  struct has_type;
  // branch 1
  template &lt;typename T, typename E&gt;
  struct has_type : std::false_type {};
  // branch 2
  template &lt;typename T&gt;
  struct has_type&lt;
      T, std::enable_if_t&lt;std::is_same_v&lt;typename T::type, typename T::type&gt;, T&gt;
  &gt; : std::true_type {};
  
  
  struct with_type {using type = void;};
  struct without_type {};
  
  int main()
  {
      std::cout&lt;&lt; has_type&lt; with_type &gt;::value &lt;&lt;std::endl;
      std::cout&lt;&lt; has_type&lt; without_type &gt;::value &lt;&lt;std::endl;
      return 0;
  }
  </code></pre>
  <p>I imagined, compiler will first try to use branch 2, if the type <code>T</code> has the member type <code>type</code>, we get <code>std::true_type</code>.
  Or fail to find <code>T::type</code>, then SFINAE and use branch 1, we get <code>std::false_type</code></p>
  <p>But the two output is both <code>false</code>.</p>
  <p>Is there anything I understand wrong?</p>