Boost logo

Boost Users :

Subject: Re: [Boost-users] [Bind] How do you write it?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2010-03-27 11:39:10


On Sat, Mar 27, 2010 at 3:43 AM, OvermindDL1 <overminddl1_at_[hidden]> wrote:

> C++ type signatures do not see optional parameters, thus, pretend that
> your function does not have a default value:
>
> #include <algorithm>
> #include <vector>
> #include "boost/bind.hpp"
>
> struct A
> {
> int double_it( int i, int j = 2 ) { return i * j; }
> } a;
>
> std::vector< int > v;
>
> int main( )
> {
> for ( std::vector< int >::iterator i = v.begin( ); i != v.end( ); ++ i )
> {
> a.double_it( * i );
> }
>
> // Write it as a for_each/bind
> std::for_each( v.begin(), v.end(), boost::bind( & A::double_it,
> boost::ref( a ), _1, 2 ) );
> }
>

Excellent, that is genuinely useful info, thanks. I've actually rewritten my
code
to avoid the need for binding with defaulted args, but at least I now know
how to do it.

- Rob.

-- 
ACCU - Professionalism in programming - http://www.accu.org


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