Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-09-13 08:27:45


I think it is better to pass the value as const reference to Save instead
copying it.

On 9/13/07, David Klein <dave_chp_at_[hidden]> wrote:
>
> Hughes, James wrote:
> > I have a question for boost:binders out there... In the following
> > scenario..(pseudocode)
> >
> > Class Fred
> > {
> > typedef std::map<wstring, shared_ptr<SomeType> > 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net