Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-17 14:43:38


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, April 17, 2002 8:13 PM
Subject: Re: [boost] Re: Loki Functor

> > My dream:
> >
> > template <class T, class U>
> > void Foo(T parm1, U parm2)
> > { ... }
> >
> > boost::bind(Foo, _1, _2)(20, 30); // call Foo<int,int>(20,30), type
> > deduction at call-time
>
> Can't do that currently. 'Foo' is not representable as a value. The
closest
> is
>
> struct Foo
> {
> template<class T, class U> void operator()(T, U);
> };
>
> bind(Foo(), _1, _2);

That's right and it's the obvious solution for my example. Actually, I think
I did the wrong one: my problem was about being able to store a function
template within a functor, with call-time type deduction. The result of
bind(Foo(), _1, _2) postpones the deduction as expected, but can't be
assigned to any boost::function<>, as far as I know. It would be cool to be
able to specify something like:

function<void, any, any> func = bind(Foo(), _1, _2);

And then call func() with any couple of parameters. It would fit exactly my
needs.

And, let me add, this "always-make-a-functor-around-your-template-function"
issue is annoying. Do you know if there are any plans to modify this in the
future?

> The problem here is that EDG considers Foo<int, int> a set of overloaded
> functions (even when it contains a single element.) You need to
> disambiguate:

> void (*f) (int, int) = Foo<int, int>;
> bind(f, _1, _2);

Thanks, much easier syntax. Do you know if this is a bug of EDG, or just an
"allowed" interpretation of the standard? If it is not covered at all, it
looks like a feasable DR to me.

Giovanni Bajo


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