title: How to check whether operator== exists?
body: <p>I am trying to create an example, which would check the existence of the <code>operator==</code> (member or, non-member function). To check whether a class has a member <code>operator==</code> is easy, but how to check whether it has a non-member <code>operator==</code>?</p>
  
  <p>This is what I have to far :</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A
  {
      int  a;
  
      #if 0
      bool operator==( const A&amp; rhs ) const
      {
          return ( a==rhs.a);
      }
      #endif
  };
  #if 1
  bool operator==( const A &amp;l,const A &amp;r )
  {
      return ( l.a==r.a);
  }
  #endif
  
  
  template &lt; typename T &gt;
  struct opEqualExists
  {
      struct yes{ char a[1]; };
      struct no { char a[2]; };
  
      template &lt;typename C&gt; static yes test( typeof(&amp;C::operator==) );
      //template &lt;typename C&gt; static yes test( ???? );
      template &lt;typename C&gt; static no test(...);
  
      enum { value = (sizeof(test&lt;T&gt;(0)) == sizeof(yes)) };
  };
  
  int main()
  {
      std::cout&lt;&lt;(int)opEqualExists&lt;A&gt;::value&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>Is it possible to write a test function to test the existence of non-member <code>operator==</code>?
  If yes, how?</p>
  
  <p>btw I have checked similar questions, but haven't found a proper solution :<br>
  <a href="https://stackoverflow.com/questions/4434569/is-it-possible-to-use-sfinae-templates-to-check-if-an-operator-exists">Is it possible to use SFINAE/templates to check if an operator exists?</a>  </p>
  
  <p>This is what I tried :  </p>
  
  <pre><code>template &lt;typename C&gt; static yes test( const C*,bool(*)(const C&amp;,constC&amp;) = &amp;operator== );
  </code></pre>
  
  <p>but the compilation fails if the non-member operator== is removed</p>