title: Function overloading - order of definitions
body: <p>I am trying to create a library which has some complex <code>resolve</code> function, that calls a simple <code>foo</code> function. The <code>resolve</code> function should work for any type for which <code>foo</code> is overloaded.</p>
  
  <p>The <code>foo</code> provided in the library works with some basic types, but I want the user to be able to provide its own, overloaded versions of <code>foo</code> that could be used in <code>resolve</code>.</p>
  
  <p>Here is a very short example:</p>
  
  <pre><code>//IN THE LIBRARY
  #include &lt;iostream&gt;
  
  void foo(int i) { std::cout &lt;&lt; "int " &lt;&lt; i; }
  void foo(float f) { std::cout &lt;&lt; "float " &lt;&lt; f; }
  
  template &lt;typename T&gt;
  void resolve(T arg) {
      //some complex computation
      foo(arg);
      //some more complutation
  }
  
  //IN THE USER CODE
  
  void foo(const char* c) { std::cout &lt;&lt; "cstring " &lt;&lt; c; }
  
  int main() {
      resolve(3);
      resolve(4.2f);
      resolve("abc");
      return 0;
  }
  </code></pre>
  
  <p>The problem is, that the user-defined overload for <code>foo</code> appears after the definition of <code>resolve</code> and it is not seen. I was expecting that at the time of instantiation <code>resolve&lt;const char*&gt;</code> the 3-rd overload of <code>foo</code> would be seen &ndash; but that is seems not to be the case:</p>
  
  <pre><code>prog.cpp: In instantiation of ‘void resolve(T) [with T = const char*]’:
  prog.cpp:16:15:   required from here
  prog.cpp:8:5: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
    foo(arg);
    ~~~^~~~~
  prog.cpp:3:6: note:   initializing argument 1 of ‘void foo(int)’
   void foo(int i) { std::cout &lt;&lt; "int " &lt;&lt; i; }
        ^~~
  </code></pre>
  
  <p>So, my question is, how can I make it work? Is there some easy way of having parts of <code>resolve</code> to be user-provided (e.g. in terms of <code>foo</code> overloading)?</p>
  
  <p>Some constraints:</p>
  
  <ul>
  <li>I want it to be resolved at compile-time.</li>
  <li>It should be as simple as possible in user code. For example, having <code>resolve</code> take an additional lambda parameter &ndash; which should always be the same for a given type of <code>arg</code> &ndash; is too complex in use.</li>
  </ul>
  
  <p>The use scenario is similar to overloading the <code>std::less</code> for given custom <code>T</code>, and then using <code>std::sort</code> without taking any additional arguments, besides the array of <code>T</code> that should be sorted.</p>