title: is_enum causing incorrect behavior for SFINAE application?
body: <p>I have been playing around with SFINAE applied to the "has_member" type of structs as described <a href="https://stackoverflow.com/q/257288/1695375">here</a>.</p>
  
  <p>So I was trying to use some of the features of c++11 to make these solutions simpler. Having some problems with checking for existence of an enum, but I can't seem to locate my logic error here. Code is:</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  template&lt;typename T &gt;
  struct has_enum_name
  {
  private:
    // ***** this is the line that isn't working *****
    // If U has an enum "name", then I expect is_enum to return true…
    // Then I expect enable_if&lt;&gt;::type to be std::true_type…etc. This isn't what happens.
    template&lt;typename U&gt; static auto test(int) -&gt; decltype(
      std::enable_if&lt;std::is_enum&lt; typename U::name &gt;::value, std::true_type&gt;::type() );
  
    template&lt;typename U&gt; static auto test(...) -&gt; std::false_type;
  public:
    static constexpr bool value = 
      !(std::is_same&lt;decltype(test&lt;T&gt;(0)),std::false_type&gt;::value);
  
    static constexpr bool is_enum()
    {
      return std::is_enum&lt;typename T::name&gt;::value;
    }
  };
  
  template&lt;typename T &gt;
  struct has_enum_name_2
  {
  private:
    template&lt;typename U&gt; static auto test(int) -&gt; decltype( 
      std::enable_if&lt;true, std::true_type&gt;::type() );
  
    template&lt;typename U&gt; static auto test(...) -&gt; std::false_type;
  public:
    static constexpr bool value = 
      !(std::is_same&lt;decltype(test&lt;T&gt;(0)),std::false_type&gt;::value);
  };
  
  struct Foo
  {
    enum class name
    {
      enum1,
      enum2
    };
  };
  
  int main()
  {
    std::cout&lt;&lt;"std::is_enum&lt;Foo::name&gt;::value = "&lt;&lt;std::is_enum&lt;Foo::name&gt;::value&lt;&lt;std::endl;
    std::cout&lt;&lt;"has_enum_name&lt;Foo&gt;::value      = "&lt;&lt;has_enum_name&lt;Foo&gt;::value&lt;&lt;std::endl;
    std::cout&lt;&lt;"has_enum_name&lt;Foo&gt;::is_enum()  = "&lt;&lt;has_enum_name&lt;Foo&gt;::is_enum()&lt;&lt;std::endl;
    std::cout&lt;&lt;"has_enum_name_2&lt;Foo&gt;::value    = "&lt;&lt;has_enum_name_2&lt;Foo&gt;::value&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>Running this using gcc 4.9.2 gives</p>
  
  <pre><code>$ ./a.out 
  std::is_enum&lt;Foo::name&gt;::value = 1
  has_enum_name&lt;Foo&gt;::value      = 0
  has_enum_name&lt;Foo&gt;::is_enum()  = 1
  has_enum_name_2&lt;Foo&gt;::value    = 1
  </code></pre>
  
  <p>The first output line verifies that the std::is_enum works correctly for the Foo::name enum.</p>
  
  <p>The second line outputs the results of struct constexpr "has_enum_name::value". I am just trying to use std::enable_if in conjunction with std::is_enum to make the decltype return something…in this case std::true_type(). As you can see, the output returns false…so the line:</p>
  
  <pre><code>template&lt;typename U&gt; static auto test(int) -&gt; decltype( 
    std::enable_if&lt;std::is_enum&lt; typename U::name &gt;::value, std::true_type&gt;::type() );
  </code></pre>
  
  <p>isn't working out like i think it should. I think that is_enum should return true, which means that enable_if should return true_type, and decltype should return true_type().</p>
  
  <p>Next output is just a check to see if std::is_enum&lt;> is working correctly in the struct…it is.</p>
  
  <p>Next output is just a copy of the "has_enum_name" struct, but I replaced the is_enum&lt;> in the suspect line with a hard coded "true"…and it works correctly.</p>
  
  <p>So for some reason, it appears that is_enum is not working returning true. Any ideas what I am doing wrong here?</p>