Re: [sigc] How to use sigc::bind<>
- From: Martin Schulze <martin-ml hippogriff de>
- To: joey yandle <jwy divisionbyzero com>
- Cc: Murray Cumming Comneon com, jcf tpg com au, libsigc-list gnome org
- Subject: Re: [sigc] How to use sigc::bind<>
- Date: Tue, 11 Nov 2003 23:20:37 +0100
Hi!
Thanks for all your input on the subject. I think consensus can be
reached about the sigc::bind() and sigc::hide() API with the following
change I'm about to commit to cvs:
* sigc++/adaptors/macros/[bind,hide].h.m4: Change to zero-based
argument index in numbered bind() and hide() overload
(Agreement on the mailing list).
Support binding up to CALL_SIZE arguments with one bind adaptor.
(Requested by joey yandle and others).
Only support binding of multiple arguments in unnumberd overloads
to keep the API simple (Requested by Murray Cumming).
Now the sigc::bind() API looks as follows:
sigc::bind() alters an arbitrary functor by fixing arguments to
certain values.
Up to 7 arguments can be bound at a time.
For single argument binding overloads of sigc::bind() are provided
that let you
specify the zero-based position of the argument to fix with the
first template parameter.
(A value of @p -1 fixes the last argument so sigc::bind<-1>() gives
the same result as sigc::bind().)
The types of the arguments can optionally be specified if not
deduced.
Examples:
void foo(int, int, int);
// single argument binding ...
sigc::bind(&foo,1)(2,3); //fixes the last (third) argument and
calls foo(2,3,1)
sigc::bind<-1>(&foo,1)(2,3); //same as bind(&foo,1)(2,3) (calls foo
(2,3,1))
sigc::bind<0>(&foo,1)(2,3); //fixes the first argument and calls
foo(1,2,3)
sigc::bind<1>(&foo,1)(2,3); //fixes the second argument and calls
foo(2,1,3)
sigc::bind<2>(&foo,1)(2,3); //fixes the third argument and calls
foo(2,3,1)
// multi argument binding ...
sigc::bind(&foo,1,2)(3); //fixes the last two arguments and
calls foo(3,1,2)
sigc::bind(&foo,1,2,3)(); //fixes all three arguments and calls
foo(3,1,2)
Cheers!
Martin
Am 2003.11.11 21:39 schrieb(en) joey yandle:
>
> Please do consider not including an API if it can't be done simply.
Really,
> who needs to bind more than 1 argument?
>
I bind multiple arguments quite frequently. In gtkmail, there's one
place
where I have to bind 5 arguments, and it's quite painful given the
current "only bind two args" usage:
SigC::Slot5<void,std::string,std::string,std::string,
std::string,unsigned
int> s5 =
SigC::slot(&jlib::net::smtp::send);
SigC::Slot3<void,std::string,std::string,std::string> s3;
std::string smtp_server =
Config::global.find(m_box->get_name())->get_smtp();
s3 = SigC::bind(s5,smtp_server,25);
SigC::Slot1<void,std::string> s1 =
SigC::bind(s3,rcpt,m_email.raw());
SigC::Slot0<void> s0 = SigC::bind(s1,mail);
It would be twice as irritating if I could only bind 1 at a time, and
much
more pleasant if I could bind as many as I needed...
--
joey yandle ___====-_ _-====___
www.divisionbyzero.com _--~~~#####// \\#####~~~--_
/joey/pubkey.asc _-~##########// ( ) \\##########~-_
-############// :\^^/: \\############-
_~############// (@::@) \\############~_
~#############(( \\// ))#############~
-###############\\ (^^) //###############-
-#################\\ / "" \ //#################-
-###################\\/ \//###################-
_#/:##########/\######( /\ )######/\##########:\#_
:/ :#/\#/\#/\/ \#/\##\ : : /##/\#/ \/\#/\#/\#: \:
" :/ V V " V \#\: : : :/#/ V " V V \: "
" " " " \ : : : : / " " " "
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]