Hi!<div><br></div><div>That one works with g++. It uses Barton-Nachman trick to make a find a better match by introducing a non-template function parameter Derived.</div><div><br></div><div><br></div><div><br></div><div><div> #include <deque></div><div>#include <boost/algorithm/string/find.hpp></div><div>#include <boost/operators.hpp></div><div><br></div><div>template<class Derived></div><div>struct helper : boost::equality_comparable<Derived></div> <div>{</div><div>��template<class Rng></div><div>��friend typename boost::range_iterator<Rng>::type find(Rng& rng, Derived const& d)</div><div>��{</div><div>�� �return std::find(boost::begin(rng), boost::end(rng), d);</div> <div>��}</div><div>};</div><div><br></div><div><br></div><div><br></div><div>struct STest : helper<STest></div><div>{</div><div>�� bool operator==(STest const& test) const { return true; }</div><div><br></div><div> };</div><div><br></div><div>int main() {</div><div>�� std::deque<STest> deq;</div><div>�� find( deq, STest() );</div><div>}</div><div><br></div><div><br></div><div>Good Luck,</div><div>Ovanes</div><br><div class="gmail_quote"> On Thu, Apr 1, 2010 at 6:12 PM, Volker Sch�ch <span dir="ltr"><<a href="mailto:vschoech@think-cell.com">vschoech@think-cell.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <div lang="EN-US" link="blue" vlink="purple"> <div> <p class="MsoNormal">Hi all,</p> <p class="MsoNormal">given this code...</p> <p class="MsoNormal">�</p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">#include</span><span style="font-size:10.0pt;font-family:"Courier New""> <span style="color:#A31515"><deque></span></span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">#include</span><span style="font-size:10.0pt;font-family:"Courier New""> <span style="color:#A31515"><boost/algorithm/string/find.hpp></span></span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">#include</span><span style="font-size:10.0pt;font-family:"Courier New""> <span style="color:#A31515"><boost/operators.hpp></span></span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#A31515">�</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">template</span><span style="font-size:10.0pt;font-family:"Courier New"">< <span style="color:blue">class</span> Rng, <span style="color:blue">class</span> T ></span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">typename</span><span style="font-size:10.0pt;font-family:"Courier New""> boost::range_iterator<Rng>::type find( Rng& rng, T <span style="color:blue">const</span>& t ) {</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">����� <span style="color:blue">return</span> std::find( boost::begin(rng), boost::end(rng), t );</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">}</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">�</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">struct</span><span style="font-size:10.0pt;font-family:"Courier New""> STest : boost::equality_comparable<STest></span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">{</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">����� <span style="color:blue">bool</span> <span style="color:blue">operator</span>==(STest <span style="color:blue">const</span>& test) <span style="color:blue">const</span> { <span style="color:blue">return</span> <span style="color:blue">true</span>; }</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">};</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">�</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">void</span><span style="font-size:10.0pt;font-family:"Courier New""> main() {</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">����� std::deque<STest> deq;</span></p> <p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">����� find( deq, STest() );</span></p> <p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">}</span></p> <p class="MsoNormal">�</p> <p class="MsoNormal">...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).</p> <p class="MsoNormal">�</p> <p class="MsoNormal">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).</p> <p class="MsoNormal">�</p> <p class="MsoNormal">Opinions? Suggestions?</p> <p class="MsoNormal">Thanks a lot,</p> <p class="MsoNormal">�� Volker</p> </div> <p style="font-size:10pt;font-family:Tahoma,Verdana,Arial">--<br>Volker Sch�ch (<a href="mailto:vschoech@think-cell.com" target="_blank">vschoech@think-cell.com</a>)<br>Senior Software Engineer </p><table style="font-size:10pt;font-family:Tahoma,Verdana,Arial" cellspacing="0"> <tbody> <tr> <td style="padding-right:10pt">think-cell Software GmbH</td> <td colspan="2"><a href="http://www.think-cell.com/" target="_blank">http://www.think-cell.com</a></td></tr> <tr> <td style="padding-right:10pt">Chausseestr. 8/E</td> <td style="padding-right:5pt">phone</td> <td>+49 30 666473-10</td></tr> <tr style="min-height:20pt" valign="top"> <td style="padding-right:10pt">10115 Berlin, Germany</td> <td style="padding-right:5pt">toll-free (US)</td> <td>+1 800 891 8091</td></tr> <tr> <td colspan="3">Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl</td></tr> <tr> <td colspan="3">Amtsgericht Berlin-Charlottenburg, HRB 85229</td></tr></tbody></table></div> <br>_______________________________________________<br> Boost-users mailing list<br> <a href="mailto:Boost-users@lists.boost.org">Boost-users@lists.boost.org</a><br> <a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br></blockquote></div><br></div>