title: Template argument deduction from pointer to member function with const and non-const versions
body: <p>I have a code like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T, typename FT&gt;
  void test( const FT &amp; (T::*ptr)() const )
  {
      std::cout &lt;&lt; "const exists" &lt;&lt; std::endl;
  }
  
  template &lt;typename T, typename FT&gt;
  void test( FT &amp; (T::*ptr)() )
  {
      std::cout &lt;&lt; "non-const exists" &lt;&lt; std::endl;
  }
  
  
  struct A {
      const double &amp; a() const { return a_; }
      double &amp; a() { return a_; }
  
      private:
          double a_;
  };
  
  struct B {
      const double &amp; b() const { return b_; }
  
      private:
          double b_;
  };
  
  
  
  int main( int argc, char **argv )
  {
      test(&amp;A::a);
      test(&amp;B::b);
  
      return 0;
  }
  </code></pre>
  
  <p>Which does not compile with <a href="http://ideone.com/phP8K" rel="nofollow">error message</a>:</p>
  
  <pre><code>prog.cpp: In function ‘int main(int, char**)’:
  prog.cpp:35: error: call of overloaded ‘test(&lt;unresolved overloaded function type&gt;)’ is ambiguous
  prog.cpp:4: note: candidates are: void test(const FT&amp; (T::*)()const) [with T = A, FT = double]
  prog.cpp:10: note:                 void test(FT&amp; (T::*)()) [with T = A, FT = double]
  </code></pre>
  
  <p>It is quite clear why compiler doesn't know what to do.
  My question is how to call the one with <code>non-const exists</code> if there is non-const version and <code>const exists</code> if there is only const version?</p>
  
  <p>Note: for this question I assume that non-const version cannot exist without const version. However if you have a solution for more general case when you can differentiate also the case when the non-const exists but const does not it would be also appreciated.</p>