Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: pass all co...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 16 Topic 9592 of 10094
Post > Topic >>

Re: pass all container elements to member function (for_each and mem_fun_ref)

by Carl Barron <cbarron413@[EMAIL PROTECTED] > May 14, 2008 at 08:57 AM

In article <68ucpiF2uqor6U1@[EMAIL PROTECTED]
>, Oncaphillis
<oncaphillis@[EMAIL PROTECTED]
> wrote:

> > If you'd like to have access to the current Holder object
> > you might want to define a void operator()(Simple &)
> > and simply call
> > 
> >     for_each(vec.begin(), vec.end(), *this);
> > 
> 
>   Which isn't such a brilliant idea as find out now,
> since for_each returns *this by value i.e. a *copy*
> of Holder in your case including the contained
> vector.
> 
> So the functor should be light weight.
> 
    so add with public access
    struct do_op
    {
       ClassName * p;
       do_op(ClassName *a):p(a){}
       void operator () (S x)
       {   p-> do_one(x);}
    };

    void do_all()
    {
       std::for_each(vec.begin(),vec.end(),do_op(this));
    }
};
do_op is lightweight as long as do_one does not invalidate any
iterator in sequence [vec.begin(),vec.end() ) ,

> O.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 16 Posts in Topic:
pass all container elements to member function (for_each and m
Nikola <popizdeh@[EMAI  2008-05-12 09:28:02 
Re: pass all container elements to member function (for_each an
Francis Glassborow <fr  2008-05-13 10:57:34 
Re: pass all container elements to member function (for_each an
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-13 10:56:39 
Re: pass all container elements to member function (for_each an
Marcin Swiderski <sfid  2008-05-13 10:55:57 
Re: pass all container elements to member function (for_each
Oncaphillis <oncaphill  2008-05-13 10:53:40 
Re: pass all container elements to member function (for_each an
"Jeff Baker" &l  2008-05-13 11:57:27 
Re: pass all container elements to member function (for_each and
Chris Uzdavinis <cuzda  2008-05-13 11:57:28 
Re: pass all container elements to member function (for_each an
d04rp@[EMAIL PROTECTED]   2008-05-13 11:57:28 
Re: pass all container elements to member function (for_each
Oncaphillis <oncaphill  2008-05-13 21:09:43 
Re: pass all container elements to member function (for_each an
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-13 21:07:38 
Re: pass all container elements to member function (for_each
Carl Barron <cbarron41  2008-05-14 08:57:27 
Re: pass all container elements to member function (for_each and
Ulysses4ever@[EMAIL PROTE  2008-05-14 15:12:52 
Re: pass all container elements to member function (for_each and
Krzysztof Czainski <1c  2008-05-14 15:12:02 
Re: pass all container elements to member function (for_each an
Sashi Asokarajan <sash  2008-05-14 17:53:08 
Re: pass all container elements to member function (for_each and
Mateusz Adamczyk <mate  2008-05-14 17:53:27 
Re: pass all container elements to member function (for_each and
Mathias Gaunard <loufo  2008-05-14 17:52:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:00:59 CDT 2008.