Re: [Boost-users] Help

"Peter Dimov"
I have a problem. Here is example of my code:
Now I want to output to a stream some fields of CAddress class. I can get a reference to CAddress object with the CItem::GetAddress method. So I am writing something like it:
apReports.push_back(make_report(boost::bind(&CAddress::GetName,boost::mem_fun(&CItem::GetAddress))); apReports.push_back(make_report(boost::bind(&CAddress::GetSize,boost::mem_fun(&CItem::GetAddress)));
these 2 lines are not compiled.
Use
boost::bind( &CAddress::GetName, boost::bind( &CItem::GetAddress, _1 ) )
Peter, you are better! I think that should be simple solution. Thank you! Now I want to write something more difficult: apReports.push_back(make_report(boost::lambda::bind(&CItem::GetItemCount)*boost::lambda::bind((&CItem::GetItemBytes))); or apReports.push_back(make_report(boost::lambda::bind(&CItem::GetItemCount)*100.0/boost::lambda::bind((&CItem::GetTotalCount))); Is there any way to make it with boost library? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users ----------

Sergey Ostrovskiy wrote:
Now I want to write something more difficult:
apReports.push_back(make_report(boost::lambda::bind(&CItem::GetItemCount)*boost::lambda::bind((&CItem::GetItemBytes)));
boost::lambda::bind(&CItem::GetItemCount, _1) * boost::lambda::bind((&CItem::GetItemBytes, _1)
or
apReports.push_back(make_report(boost::lambda::bind(&CItem::GetItemCount)*100.0/boost::lambda::bind((&CItem::GetTotalCount)));
boost::lambda::bind(&CItem::GetItemCount, _1)*100.0/boost::lambda::bind((&CItem::GetTotalCount, _1) but, depending on your argument type, it may need further fixes, such as using *_1 instead. lambda::bind doesn't handle smart pointers as 'this' well.
participants (2)
-
Peter Dimov
-
Sergey Ostrovskiy