Re: [sigc] How to use sigc::bind<>



Am 2003.11.09 11:50 schrieb(en) Murray Cumming Comneon com:
> [mailto:libsigc-list-admin gnome org] On Behalf Of Jeff Franks
> Martin Schulze wrote:
>
> >   void bar(int,int);
> >   some_signal.connect(sigc::bind<0>(&bar,10,20));
> >     // binds two arguments at a time
> >
> >   sigc::signal<void,int> other_signal;
> >   other_signal.connect(sigc::bind<0>(&bar,20));
> >     // binds to the last (second) argument of bar
> >   other_signal.connect(sigc::bind<1>(&bar,10));
> >     // binds to the first argument of bar
> >
> This is where I had confusion, bind<0> binds to the last
> argument, not
> the first, as zero might imply. I find the explanation bind<0>
(zero)
> binds to the last (second) argument of bar confusing. Compared with
> bind<1> (first) binds to the first argument of bar, which sounds
> logical. Initially I thought that the # in bind<#> meant that
> you could
> specify which argument position in the bound function the
> bound argument
> would be passed to, such as zero for the first, 1 for the
> second, 2 for
> the third, etc, like a zero-based index. That would leave bind<#> to

> create a slot functor with one less argument, based on the remaining

> arguments, as is required.
>
> I'm sure this will confuse many programmers.

It confuses me.

1) It is a neat feature to able to specify the number of the argument
   to be fixed.
2) There _needs_ to be a magical number for # specifying that the
   the last argument should be fixed for convenience and for the case
   that the number of arguments is not known.

The current syntax is
"0" for the last argument,
"1" for the first,
"2" for the second,
etc.

The only alternative to the current syntax I see is to use
"-1" for the last argument,
"0" for the first,
"1" for the second,
etc.

I prefer it the way it is currently implemented. IMO, it is very
straight-forward. Propositions for a different syntax are welcome.

Regards,

  Martin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]