Boost logo

Boost :

From: Hervé Brönnimann (hervebronnimann_at_[hidden])
Date: 2006-12-09 09:32:22


Indeed, I tried and to my surprise it doesn't work (both boost::bind
(&draw, _1, _2)(1,2,3,4) and boost::bind<void>(&draw, _1, _2)(1,2,3,4)).

But there is no reason (other than design) it couldn't. In fact, our
company's version of bind (I mean at Bloomberg LP) *does* allow extra
arguments to be passed to a non-explicit binder (i.e. one whose
signature cannot be determined from the bound object at binding
time). The extra unused arguments are simply dropped.

Now I could imagine that the authors of boost.bind do *not* want to
allow this for type safety reasons, i.e. matching the signature
exactly. That would be understandable. In that case I'd say you
have a point.

--
Hervé Brönnimann
hervebronnimann_at_[hidden]
On Dec 8, 2006, at 5:37 AM, ali f wrote:
> Boost.Bind can indeed be used to decrease the number of args a  
> function can
> take, but it can't be used to increase the number of args a  
> function can
> take. In the example I gave in my original post, the callback:
>
> bool callback(int,int,bool,int);
>
> and you have a functon
>
> bool draw(int,int)
>
> You can't use bind to assign "draw" to "callback". args_cast can be  
> used
> though.
>
> - ali
>
> ----- Original Message -----
> From: "me22" <me22.ca_at_[hidden]>
> Newsgroups: gmane.comp.lib.boost.devel
> Sent: Friday, December 08, 2006 6:30 PM
> Subject: Re: new utility: function parameter caster
>
>
>> On 12/7/06, ali f <k9eks_at_[hidden]> wrote:
>>> a) wrap the function in a struct and overload operator ()
>>> b) change the signature (but then change all places where you've  
>>> invoked
>>> the
>>> function already)
>>>
>> c) Use Boost.Bind.
>>
>>> From http://boost.org/libs/bind/bind.html#with_functions :
>> bind(f, _2, _1)(x, y);                 // f(y, x)
>> bind(g, _1, 9, _1)(x);                 // g(x, 9, x)
>> bind(g, _3, _3, _3)(x, y, z);          // g(z, z, z)
>> bind(g, _1, _1, _1)(x, y, z);          // g(x, x, x)
>> Note that, in the last example, the function object produced by
>> bind(g, _1, _1, _1) does not contain references to any arguments
>> beyond the first, but it can still be used with more than one
>> argument. Any extra arguments are silently ignored, just like the
>> first and the second argument are ignored in the third example.
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/ 
> listinfo.cgi/boost

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk