Boost logo

Boost Users :

Subject: [Boost-users] inappropriate ADL
From: Volker Schöch (vschoech_at_[hidden])
Date: 2010-04-01 12:12:06


Hi all,

given this code...

 

#include <deque>

#include <boost/algorithm/string/find.hpp>

#include <boost/operators.hpp>

 

template< class Rng, class T >

typename boost::range_iterator<Rng>::type find( Rng& rng, T const& t ) {

      return std::find( boost::begin(rng), boost::end(rng), t );

}

 

struct STest : boost::equality_comparable<STest>

{

      bool operator==(STest const& test) const { return true; }

};

 

void main() {

      std::deque<STest> deq;

      find( deq, STest() );

}

 

...the VS9 compiler fails with "error C2668: 'find' : ambiguous call to overloaded function". This is due to the fact that STest inherits from a type that is defined in boost namespace which triggers the compiler to try ADL which finds boost::algorithm::find(RangeT& Input, const FinderT& Finder).

 

An obvious solution is to prefix the call to find(...) with ::, but this feels wrong: It does not make sense that the compiler does ADL in this case. There is nothing special about boost::equality_comparable<...> that would make it a more natural argument for boost::algorithm::find(RangeT& Input, const FinderT& Finder) than any other type, and there is nothing special about boost::algorithm::find(RangeT& Input, const FinderT& Finder) that would make it a more natural find implementation for boost::equality_comparable<...> than my find(Rng& rng, T const& t). Maybe the function and the type should not be in the same namespace in the first place. Currently, the mere presence of the specific implementation boost::algorithm::find(RangeT& Input, const FinderT& Finder) disallows the implementation of the canonical find(Rng& rng, T const& t).

 

Opinions? Suggestions?

Thanks a lot,

   Volker

--
Volker Schöch · vschoech_at_[hidden]
Senior Software Engineer
 
think-cell Software GmbH · Chausseestr. 8/E · 10115 Berlin, Germany 
http://www.think-cell.com · phone +49 30 666473-10 · toll-free (US) +1 800 891 8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Berlin-Charlottenburg, HRB 85229


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net