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 &lt;deque&gt;</div><div>#include &lt;boost/algorithm/string/find.hpp&gt;</div><div>#include &lt;boost/operators.hpp&gt;</div><div><br></div><div>template&lt;class Derived&gt;</div><div>struct helper : boost::equality_comparable&lt;Derived&gt;</div>
<div>{</div><div>��template&lt;class Rng&gt;</div><div>��friend typename boost::range_iterator&lt;Rng&gt;::type find(Rng&amp; rng, Derived const&amp; 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&lt;STest&gt;</div><div>{</div><div>�� bool operator==(STest const&amp; test) const { return true; }</div><div><br></div><div>
};</div><div><br></div><div>int main() {</div><div>�� std::deque&lt;STest&gt; 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">&lt;<a href="mailto:vschoech@think-cell.com">vschoech@think-cell.com</a>&gt;</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:&quot;Courier New&quot;;color:blue">#include</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> <span style="color:#A31515">&lt;deque&gt;</span></span></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">#include</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> <span style="color:#A31515">&lt;boost/algorithm/string/find.hpp&gt;</span></span></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">#include</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> <span style="color:#A31515">&lt;boost/operators.hpp&gt;</span></span></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#A31515">�</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">template</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">&lt; <span style="color:blue">class</span>
Rng, <span style="color:blue">class</span> T &gt;</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">typename</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> boost::range_iterator&lt;Rng&gt;::type find(
Rng&amp; rng, T <span style="color:blue">const</span>&amp; t ) {</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">����� <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:&quot;Courier New&quot;">}</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">�</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">struct</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> STest : boost::equality_comparable&lt;STest&gt;</span></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">{</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">����� <span style="color:blue">bool</span> <span style="color:blue">operator</span>==(STest <span style="color:blue">const</span>&amp;
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:&quot;Courier New&quot;">};</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">�</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue">void</span><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;"> main() {</span></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">����� std::deque&lt;STest&gt; deq;</span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">����� find( deq, STest() );</span></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:&quot;Courier New&quot;">}</span></p>

<p class="MsoNormal">�</p>

<p class="MsoNormal">...the VS9 compiler fails with �error C2668: &#39;find&#39; :
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&amp; Input, const
FinderT&amp; 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&lt;�&gt;
that would make it a more natural argument for boost::algorithm::find(RangeT&amp;
Input, const FinderT&amp; Finder) than any other type, and there is nothing
special about boost::algorithm::find(RangeT&amp; Input, const FinderT&amp;
Finder) that would make it a more natural find implementation for boost::equality_comparable&lt;�&gt;
than my find(Rng&amp; rng, T const&amp; 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&amp; Input, const
FinderT&amp; Finder) disallows the implementation of the canonical find(Rng&amp;
rng, T const&amp; 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>