Boost logo

Boost :

From: Arturo_Cuebas_at_[hidden]
Date: 2004-08-19 10:17:14


"Jonathan Turkanis" <technews_at_[hidden]> wrote in message
news:cg0tk6$98j$1_at_sea.gmane.org...
>
> "Peter Dimov" <pdimov_at_[hidden]> wrote in message
> news:002301c4857d$234e3270$0600a8c0_at_pdimov...
>>
>> Did you know that it already works? ;-)
>
> Yes, naturally. ;-)
>
> Jonathan
 
If I'm interpretting this correctly, this means that arity isn't an issue.
In that case, maybe this implementation will work:
 
template<typename P, typename C, typename R>
boost::function<R (C *, P)> overload_select(R (C::* f)(P))
{
   return boost::bind(f, _1, _2);
}
 
template<typename P1, typename P2, typename C, typename R>
boost::function<R (C *, P1, P2)> overload_select(R (C::* f)(P1, P2))
{
   return boost::bind(f, _1, _2, _3);
}
 
...etc. And for free functions:
 
template<typename P, typename R>
boost::function<R (P)> overload_select(R (*f)(P))
{
   return boost::bind(f, _1);
}
 
template<typename P1, typename P2, typename R>
boost::function<R (P1, P2)> overload_select(R (*f)(P1, P2))
{
   return boost::bind(f, _1, _2);
}
 
...etc.
 
This would break this:

struct V
{
   void f(void){}
   void f(char){}
};
int main()
{
   V o;
   bind(overload_select<void>(&V::f), &o);
}

But so what? Just do this:

bind(&V::f, &o);


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