<div class="gmail_quote">On Tue, Jan 20, 2009 at 3:22 PM, Zachary Turner <span dir="ltr">&lt;<a href="mailto:divisortheory@gmail.com">divisortheory@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c"><div class="gmail_quote">On Tue, Jan 20, 2009 at 9:11 AM, Robert Jones <span dir="ltr">&lt;<a href="mailto:robertgbjones@gmail.com" target="_blank">robertgbjones@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div class="gmail_quote">On Tue, Jan 20, 2009 at 2:53 PM, Maxim Koshelev <span dir="ltr">&lt;<a href="mailto:chuchelo@gmail.com" target="_blank">chuchelo@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div>&gt; The Lambda version would be similar, just replacing the outer bind with<br>
&gt; infix notation<br>
&gt;<br>
&gt; #include &quot;boost/lambda/lambda.hpp&quot;<br>
&gt; #include &quot;boost/lambda/bind.hpp&quot;<br>
&gt;<br>
&gt; using namespace boost::lambda;<br>
&gt;<br>
&gt; std::accumulate( begin, end, _1 + bind(&amp;A::a, _2 ));<br>
&gt;<br>
&gt; Again untested.<br>
<br>
</div>this std::accumulate return complicated lambda function, but not int value :-)<br>
<br>
</blockquote></div><br></div>Yeah, sorry, missed the initial value!<br><br>std::accumulate( begin, end, 0, _1 + bind(&amp;A::a, _2 ));<br>
</blockquote></div></div></div>I still get problems.&nbsp; Mostly ambiguity issues with _1 and _2, so I qualify them with boost::lambda and then I get<br><br>boost::lambda::function_adaptor&lt;Func&gt;::apply none of the 8 overloads could convert all the argument types<br>

with<br>[<br>&nbsp;&nbsp;&nbsp; Func = int Test::*<br>]<br>could be ...<br><br>and from there it lists every possible overload of RET boost::lambda::function_adaptor&lt;Func&gt;::apply&lt;RET&gt;(T Test::*, _____)<br><br>where ____ is every possible combination of const, volatile, pointer, and reference, and the type &quot;Object&quot;.&nbsp; <br>

<br></blockquote><div><br>This one IS tested!<br><br>#include &quot;boost/lambda/lambda.hpp&quot;<br>#include &quot;boost/lambda/bind.hpp&quot;<br>#include &lt;vector&gt;<br>#include &lt;numeric&gt;<br>#include &lt;iostream&gt;<br>
<br>struct A{<br>&nbsp;int a;<br>&nbsp;std::string b;<br>};<br><br>int a_sum(int i, const A &amp;v){ return i + v.a; }<br><br>int main( )<br>{<br>&nbsp; using namespace boost::lambda;<br>&nbsp; std::vector&lt;A&gt; v;<br>&nbsp; for ( unsigned i=1; i != 6; ++i)<br>
&nbsp; {<br>&nbsp;&nbsp;&nbsp; A a = { i, &quot;&quot; };<br>&nbsp;&nbsp;&nbsp; v.push_back( a );<br>&nbsp; }<br><br>&nbsp; int result = std::accumulate(v.begin(),v.end(),0, _1 + bind(&amp;A::a,_2));<br>&nbsp; std::cout &lt;&lt; result &lt;&lt; &quot;\n&quot;;<br>}<br>&nbsp;</div>
</div>