[Boost-users] Using boost::bind with boost::function

1 view
Skip to first unread message

maruthilak...@yahoo.com

unread,
Nov 23, 2009, 7:12:28 PM11/23/09
to boost...@lists.boost.org
I'm using Boost ver 1.39.0

I have a module to which other modules can register callbacks. This module will call those callbacks with a couple of arguments - as an example

registerCallBack(void (*callbackFunc)(int));

At the time of callback it will call: (*callbackFunc)(3);

To allow for any function to be registered (each module's callback may have a different signature etc, but everyone can allow for this one last arg), I declared it to take a
boost::function<void (int)>

I was hoping that if I have a twoarg_callback(int, int) function, I can register it with the module by using boost::bind to bind the first argument, but that is not possible. I am unable to assign the return value of boost::bind to a boost::function<void (int)> object by binding one argument. However, assigning the return value of boost::bind where all the arguments of a function are bound (so the resulting object is a void() function) seems to work.

I'm trying to decipher the errors, but would appreciate any help I can get. I get errors both on VisualStudio 2008, as well as g++ 4.1.2, so I'm guessing it's not some compiler problem rather it's my usage. Attached a sample source file. I commented out the 4 lines that were giving me errors.

Thanks,
Lakshman.




The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
BindTest.cpp

Peter Dimov

unread,
Nov 23, 2009, 7:51:29 PM11/23/09
to boost...@lists.boost.org
maruthilak...@yahoo.com wrote:
...

> I was hoping that if I have a twoarg_callback(int, int) function, I
> can register it with the module by using boost::bind to bind the
> first argument, but that is not possible. I am unable to assign the
> return value of boost::bind to a boost::function<void (int)> object
> by binding one argument.

Use boost::bind( twoarg_callback, 3, _1 ). The 'int' in function<void(int)>
is the first argument and is addressed via _1. There is no second argument,
so _2 doesn't work.

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

OvermindDL1

unread,
Nov 23, 2009, 10:48:32 PM11/23/09
to boost...@lists.boost.org

And please please please do not put your emails as black text on a
transparent background. Those of us with black backgrounds see
*nothing*. If you specify a text color, then *make*certain* to
specify a background color too, but better still, send your emails as
plain text.

Steven Watanabe

unread,
Nov 23, 2009, 11:44:18 PM11/23/09
to boost...@lists.boost.org
AMDG

OvermindDL1 wrote:
> On Mon, Nov 23, 2009 at 5:12 PM, <maruthilak...@yahoo.com> wrote:
>

>> <snip>


>>
>
> And please please please do not put your emails as black text on a
> transparent background. Those of us with black backgrounds see
> *nothing*. If you specify a text color, then *make*certain* to
> specify a background color too, but better still, send your emails as
> plain text.

FWIW, that message was sent in *both* plain text and html.

In Christ,
Steven Watanabe

OvermindDL1

unread,
Nov 23, 2009, 11:52:47 PM11/23/09
to boost...@lists.boost.org
On Mon, Nov 23, 2009 at 9:44 PM, Steven Watanabe <watan...@gmail.com> wrote:
> AMDG
>
> OvermindDL1 wrote:
>>
>> On Mon, Nov 23, 2009 at 5:12 PM,  <maruthilak...@yahoo.com> wrote:
>>
>>>
>>> <snip>
>>>
>>
>> And please please please do not put your emails as black text on a
>> transparent background.  Those of us with black backgrounds see
>> *nothing*.  If you specify a text color, then *make*certain* to
>> specify a background color too, but better still, send your emails as
>> plain text.
>
> FWIW, that message was sent in *both* plain text and html.

And my client is capable of rendering HTML, but your HTML message
specified a foreground color, but no background color, thus it
defaulted to transparent, meaning that my window background color of
black shows through, so your black text was on a transparent
background, that was actually black. If you are going to specify a
foreground color in your HTML, it is best to always specify a
background color too, including on webpages as there is no actual
'default' setting for such things even in a web-browser. :)

maruthilak...@yahoo.com

unread,
Nov 24, 2009, 12:03:49 AM11/24/09
to boost...@lists.boost.org
Thanks a lot for pointing out my mistake.

About the color, I did not specify any background or foreground color. It was Yahoo! mail's default. Am trying to send this message in plain text. Will try to keep this in mind for the messages in future.

Thanks once again,
Lakshman.

________________________________
From: OvermindDL1 <overm...@gmail.com>
To: boost...@lists.boost.org
Sent: Tue, 24 November, 2009 9:18:32 AM
Subject: Re: [Boost-users] Using boost::bind with boost::function

The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

OvermindDL1

unread,
Nov 24, 2009, 11:45:19 AM11/24/09
to boost...@lists.boost.org
On Mon, Nov 23, 2009 at 10:03 PM, <maruthilak...@yahoo.com> wrote:
> Thanks a lot for pointing out my mistake.
>
> About the color, I did not specify any background or foreground color. It was Yahoo! mail's default. Am trying to send this message in plain text. Will try to keep this in mind for the messages in future.

Yeah, Yahoo sucks, so thanks for the effort from all of us that use
dark color schemes due to sensitive eyes. :)

Reply all
Reply to author
Forward
0 new messages