title: Check if a class has a method with a given name but any signature
body: <p>I'm trying to find a way to simply check if a method of a given name exists in a c++ class using c++11 features, but without(!) checking the signature.</p>
  
  <p>I was unable to find anything without the signature check, so I tried to use Valentin Milea's solution from <a href="https://stackoverflow.com/questions/87372/check-if-a-class-has-a-member-function-of-a-given-signature/10707822#10707822">here</a> and modify it (see below), but my understanding of c++ is not deep enough to really grasp what's going on there:</p>
  
  <pre><code>#include &lt;type_traits&gt;
  
  template &lt;class C&gt;
  class HasApproxEqualMethod
  {
      template &lt;class T&gt;
      static std::true_type testSignature(bool (T::*)(const T&amp;, double) const);
  
      template &lt;class T&gt;
      static decltype(testSignature(&amp;T::approx_equal)) test(std::nullptr_t);
  
      template &lt;class T&gt;
      static std::false_type test(...);
  
  public:
      using type = decltype(test&lt;C&gt;(nullptr));
      static const bool value = type::value;
  };
  
  class Base {
  public:
  virtual ~Base();
  virtual bool approx_equal(const Base&amp; other, double tolerance) const;
  };
  
  class Derived : public Base {
  public:
       // same interface as base class
      bool approx_equal(const Base&amp; other, double tolerance) const;
  };
  
  class Other {};
  
  static_assert(HasApproxEqualMethod&lt;Base&gt;().value == true, "fail Base");
  static_assert(HasApproxEqualMethod&lt;Other&gt;().value == false, "fail Other");
   // this one fails:
  static_assert(HasApproxEqualMethod&lt;Derived&gt;().value == true, "fail Derived");
  </code></pre>
  
  <p>I think the root of the problem is that my <code>approx_equal</code> uses base class references also in the derived class(es) and that doesn't match the signature anymore.</p>
  
  <p>In the end, I want to construct a template comparison function that calls <code>approx_equal</code> if it exists, or something else( e.g. <code>==</code> for strings etc., or <code>fabs(a-b) &lt;= tolerance</code> for floats and doubles). The approx_equal functions will then in turn call the template comparison for each member.</p>
  
  <p>I actually got that part to work with an ugly workaround, where each class with an <code>approx_equal</code> method also gets a member variable <code>const static char hasApproxEqualMethod</code>. Then I check if that variable exists as suggested <a href="https://stackoverflow.com/questions/50295630/specialize-function-if-argument-has-member-variable">here</a>, but that's certainly not the way to go.</p>