title: Ambiguous call to templated function due to ADL
body: <p>I've been bitten by this problem a couple of times and so have my colleagues. When compiling</p>
  
  <pre><code>#include &lt;deque&gt;
  #include &lt;boost/algorithm/string/find.hpp&gt;
  #include &lt;boost/operators.hpp&gt;
  
  template&lt; class Rng, class T &gt;    
  typename boost::range_iterator&lt;Rng&gt;::type find( Rng&amp; rng, T const&amp; t ) {
        return std::find( boost::begin(rng), boost::end(rng), t );
  }
  
  struct STest {
        bool operator==(STest const&amp; test) const { return true; }
  };
  
  struct STest2 : boost::equality_comparable&lt;STest2&gt;   {
        bool operator==(STest2 const&amp; test) const { return true; }
  };
  
  void main() {
        std::deque&lt;STest&gt; deq;
        find( deq, STest() ); // works
        find( deq, STest2() ); // C2668: 'find' : ambiguous call to overloaded function
  }
  </code></pre>
  
  <p>...the VS9 compiler fails when compiling the second find. This is due to the fact that <code>STest2</code> inherits from a type that is defined in boost namespace which triggers the compiler to try ADL which finds <code>boost::algorithm::find(RangeT&amp; Input, const FinderT&amp; Finder)</code>.</p>
  
  <p>An obvious solution is to prefix the call to <code>find(…)</code> with "<code>::</code>" but why is this necessary? There is a perfectly valid match in the global namespace, so why invoke Argument-Dependent Lookup? Can anybody explain the rationale here?</p>