<div class="gmail_quote">On Tue, Jan 20, 2009 at 3:22 PM, Zachary Turner <span dir="ltr"><<a href="mailto:divisortheory@gmail.com">divisortheory@gmail.com</a>></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"><<a href="mailto:robertgbjones@gmail.com" target="_blank">robertgbjones@gmail.com</a>></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"><<a href="mailto:chuchelo@gmail.com" target="_blank">chuchelo@gmail.com</a>></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>> The Lambda version would be similar, just replacing the outer bind with<br> > infix notation<br> ><br> > #include "boost/lambda/lambda.hpp"<br> > #include "boost/lambda/bind.hpp"<br> ><br> > using namespace boost::lambda;<br> ><br> > std::accumulate( begin, end, _1 + bind(&A::a, _2 ));<br> ><br> > 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(&A::a, _2 ));<br> </blockquote></div></div></div>I still get problems. Mostly ambiguity issues with _1 and _2, so I qualify them with boost::lambda and then I get<br><br>boost::lambda::function_adaptor<Func>::apply none of the 8 overloads could convert all the argument types<br> with<br>[<br> Func = int Test::*<br>]<br>could be ...<br><br>and from there it lists every possible overload of RET boost::lambda::function_adaptor<Func>::apply<RET>(T Test::*, _____)<br><br>where ____ is every possible combination of const, volatile, pointer, and reference, and the type "Object". <br> <br></blockquote><div><br>This one IS tested!<br><br>#include "boost/lambda/lambda.hpp"<br>#include "boost/lambda/bind.hpp"<br>#include <vector><br>#include <numeric><br>#include <iostream><br> <br>struct A{<br> int a;<br> std::string b;<br>};<br><br>int a_sum(int i, const A &v){ return i + v.a; }<br><br>int main( )<br>{<br> using namespace boost::lambda;<br> std::vector<A> v;<br> for ( unsigned i=1; i != 6; ++i)<br> {<br> A a = { i, "" };<br> v.push_back( a );<br> }<br><br> int result = std::accumulate(v.begin(),v.end(),0, _1 + bind(&A::a,_2));<br> std::cout << result << "\n";<br>}<br> </div> </div>