title: Why does template argument deduction/substitution fail here?
body: <p>I am trying to write a simple template that I can use for memoization with functions taking a single argument:</p>
  
  <pre><code>#include &lt;map&gt;          
  
  template &lt;typename F,typename OUT,typename IN&gt; 
  OUT memoization(IN in){
      static std::map&lt;IN,OUT&gt; memo;
      static typename std::map&lt;IN,OUT&gt;::iterator found = memo.find(in);
      if (found != memo.end()) { return found-&gt;second; }  
      OUT res = F(in);
      memo(in) = res;
      return res;
  }
  
  double test(double x) { return x*x; }
  
  int main(){
      for (int i=0;i&lt;5;i++){
          memoization&lt;test,double,double&gt;(i*0.5);
      }
  }
  </code></pre>
  
  <p>But i get the error: </p>
  
  <blockquote>
    <p>error: no matching function for call to 'memoization(double)'</p>
    
    <p>note: candidate is:</p>
    
    <p>note: template OUT memoization(IN)</p>
    
    <p>note:   template argument deduction/substitution failed:</p>
  </blockquote>
  
  <p><strong>Why does this fail to compile?</strong></p>
  
  <p>Actually I dont understand why template argument deduction/substitution is taking place at all when I specify all the template parameters.</p>
  
  <p>I am using gcc version 4.7.2 (no C++11 enabled)</p>
  
  <p>PS: the template has many more errors than I first realized, but I leave it as is...</p>