Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-03-20 07:12:49


Giovanni Bajo wrote:
> Hello,

Hi,

> template <typename CB>
> void Foo(CB cb)
> {
> int a=123, b=456;
>
> bind(cb, _1, _2)(a,b);
> }
>
> void Bar1(int) {}
> void Bar2(int, int) {}
>
> int main()
> {
> Foo(Bar1);
> Foo(Bar2);
> }
>
>
> The above compiles on Comeau, but fails on VC7.1 and GCC 3.2.2.

Nope, it fails on Comeau, too, but in the prelinker stage.

> - The failing compilers complain because they cannot deduce the
> return type for bind(). Expliciting it via bind<void>() turns off a
> first level of errors. Why does this happen? Which template machery
> is failing? Maybe is there a way to workaround it?

Nothing is failing; bind is being helpful by reporting the error earlier
when you allow it to.

> - After that, they complain with "too many arguments for call through
> pointers". I know that bind() silently skips exceeding arguments, but
> I
> never got if this applies to arguments at bind-time or call-time.

The problem here is that bind(Bar1, _1, _2) is invalid, since Bar1 takes one
argument, and you supply two.

If I understand your problem correctly, you need to replace

Foo(Bar1);

with

Foo(bind(Bar1, _1));

You can now remove the bind() in Foo, it is equivalent to cb(a, b).


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