www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/07/08:15:12

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "David Hilsee" <davidhilseenews AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
References: <3C624DA4 DOT CDAF6FC3 AT bigfoot DOT com> <3C62529F DOT D7F259FA AT bigfoot DOT com> <J%t88.50321$8d1 DOT 13189767 AT news1 DOT rdc1 DOT md DOT home DOT com> <3C62708F DOT 18766A42 AT bigfoot DOT com>
Subject: Re: Error with bind2nd() and ptr_fun()
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <eWu88.50489$8d1.13211020@news1.rdc1.md.home.com>
Date: Thu, 07 Feb 2002 13:03:06 GMT
NNTP-Posting-Host: 68.49.80.44
X-Complaints-To: abuse AT home DOT net
X-Trace: news1.rdc1.md.home.com 1013086986 68.49.80.44 (Thu, 07 Feb 2002 05:03:06 PST)
NNTP-Posting-Date: Thu, 07 Feb 2002 05:03:06 PST
Organization: Excite AT Home - The Leader in Broadband http://home.com/faster
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

>
> We can see that function
>  void foo1 (AAA& a)  {a.set_value (a.get_value() + 100);}
> can be used in for_each  ()
>
> So, what about
> void foo2 (AAA& a, int n) { a.set_value (a.get_value() + n); } ?
>
> Is there any way to do what I want to ?
>

Yes, but the easiest way might be re-implementing a binder:

struct AddToAAA
{
    int value;
    AddToAAA( int val ) : value(val){}
    void operator() (AAA& inst) const
    {
          inst.set_value (inst.get_value() + value);
    }
};

for_each(vect.begin(), vect.end(), AddToAAA (200));

Untested, but it should work.  You might be able to apply some templates to
make the functor more reusable.  For instance, it could take a predicate, so
you can pass things like std::plus et al instead of hard-coding the adding
operation.  I can't think of anything easier than the above, offhand.
Perhaps someone else will come along with a better idea.

--
David Hilsee


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019