title: Match type of inherited member functions
body: <p>I have the following snipped of code, which does not compile.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A {
      void foo() {}
  };
  
  struct B : public A {
      using A::foo;
  };
  
  template&lt;typename U, U&gt; struct helper{};
  
  int main() {
      helper&lt;void (A::*)(), &amp;A::foo&gt; compiles;
      helper&lt;void (B::*)(), &amp;B::foo&gt; does_not_compile;
  
      return 0;
  }
  </code></pre>
  
  <p>It does not compile since <code>&amp;B::foo</code> resolves to <code>&amp;A::foo</code>, and thus it cannot match the proposed type <code>void (B::*)()</code>. Since this is part of a SFINAE template that I am using to check for a very specific interface (I'm forcing specific argument types and output types), I would like for this to work independently of inheritances, while keeping the check readable.</p>
  
  <p>What I tried includes:</p>
  
  <ul>
  <li><p>Casting the second part of the argument:</p>
  
  <p><code>helper&lt;void (B::*)(), (void (B::*)())&amp;B::foo&gt; does_not_compile;</code></p>
  
  <p>This unfortunately does not help as the second part is now not recognized as a constant expression, and fails.</p></li>
  <li><p>I've tried assigning the reference to a variable, in order to check that.</p>
  
  <p><code>constexpr void (B::* p)() = &amp;B::foo;
   helper&lt;void (B::* const)(), p&gt; half_compiles;</code></p>
  
  <p>This code is accepted by clang 3.4, but g++ 4.8.1 rejects it, and I have no idea on who's right.</p></li>
  </ul>
  
  <p>Any ideas?</p>
  
  <p>EDIT: Since many comments are asking for a more specific version of the problem, I'll write it here:</p>
  
  <p>What I'm looking for is a way to explicitly check that a class respects a specific interface. This check will be used to verify input arguments in templated functions, so that they respect the contract that those functions require, so that compilation stops beforehand in case the class and a function are not compatible (i.e. type traits kind of checking). </p>
  
  <p>Thus, I need to be able to verify return type, argument type and number, constness and so on of each member function that I request. The initial question was the checking part of the bigger template that I'm using to verify matches.</p>