[bind] for_each, Member function question.
I have a question for boost:binders out there... In the following
scenario..(pseudocode)
Class Fred
{
typedef std::map
Hughes, James wrote:
I have a question for boost:binders out there... In the following scenario..(pseudocode)
Class Fred { typedef std::map
MyMap; MyMap Bert;
Save(MyMap::iterator pos) { ... }
SaveAll() { for_each(Bert.begin(), Bert.end(), bind(&Fred::Save, this, _1); }
};
The code wants to save all the data in the map. The bind, I was hoping, would simply call Save for all items in the map, passing in the iterator as the parameter, but I get a template compile fault on the bind. I've tried all sorts of combinations, checked boost docs, read the chapter in Beyond the C++ standard library, Googled etc, but just cannot figure out what I need to do here.
std::for_each passes the dereferenced iterator value to the function object. You'll need to at least change the signature of Save to: void Save( MyMap::value_type& val )... Jeff Flinn
Hughes, James wrote:
I have a question for boost:binders out there... In the following scenario..(pseudocode)
Class Fred { typedef std::map
MyMap; MyMap Bert;
Save(MyMap::iterator pos) { ... }
SaveAll() { for_each(Bert.begin(), Bert.end(), bind(&Fred::Save, this, _1); }
};
The code wants to save all the data in the map. The bind, I was hoping, would simply call Save for all items in the map, passing in the iterator as the parameter, but I get a template compile fault on the bind. I've tried all sorts of combinations, checked boost docs, read the chapter in Beyond the C++ standard library, Googled etc, but just cannot figure out what I need to do here.
Any help gratefully received.
James
Hi James, Class Fred { ... void // void was missing Save(MyMap::value_type pos) // changed iterator to value_type { ... } void // void was missing SaveAll() { for_each(Bert.begin(), Bert.end(), bind(&Fred::Save, this, _1); } }; -- HTH, dave
I think it is better to pass the value as const reference to Save instead
copying it.
On 9/13/07, David Klein
Hughes, James wrote:
I have a question for boost:binders out there... In the following scenario..(pseudocode)
Class Fred { typedef std::map
MyMap; MyMap Bert;
Save(MyMap::iterator pos) { ... }
SaveAll() { for_each(Bert.begin(), Bert.end(), bind(&Fred::Save, this, _1); }
};
The code wants to save all the data in the map. The bind, I was hoping, would simply call Save for all items in the map, passing in the iterator as the parameter, but I get a template compile fault on the bind. I've tried all sorts of combinations, checked boost docs, read the chapter in Beyond the C++ standard library, Googled etc, but just cannot figure out what I need to do here.
Any help gratefully received.
James
Hi James,
Class Fred { ...
void // void was missing Save(MyMap::value_type pos) // changed iterator to value_type { ... }
void // void was missing SaveAll() { for_each(Bert.begin(), Bert.end(), bind(&Fred::Save, this, _1); }
};
-- HTH, dave
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of David Klein Sent: 13 September 2007 13:49 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] for_each, Member function question.
Ovanes Markarian wrote:
I think it is better to pass the value as const reference to Save instead copying it.
Hi Ovanes,
i just wanted to show to use value_type instead of iterator. But you're right, a const ref is probably better :)
-- Regards, dave
Thanks all. I had a feeling I was missing some vital piece of information!! Rgds James This message (including any attachments) contains confidential and/or proprietary information intended only for the addressee. Any unauthorized disclosure, copying, distribution or reliance on the contents of this information is strictly prohibited and may constitute a violation of law. If you are not the intended recipient, please notify the sender immediately by responding to this e-mail, and delete the message from your system. If you have any questions about this e-mail please notify the sender immediately.
participants (4)
-
David Klein
-
Hughes, James
-
Jeff Flinn
-
Ovanes Markarian