Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-05-10 05:36:06


On Sat, May 10, 2008 at 10:43 AM, vicente.botet
<vicente.botet_at_[hidden]> wrote:
>
> Try with
> struct foo_t { template<class T> void operator()(T){} } foo;
>

boost::function<void(int)> f = foo; // ok it works, no ambiguity,
object is instantiated as foo_t::operator<int>()

boost::multi_signature_function::
function<boost::mpl::vector<void(int), void(std::string)> > msf = foo;

 // error! Ambiguous call <strip> could be void(int) or <strip>
void(std::string)

msf = f; // this works! no more ambiguity, foo_t is instantiated with T = int

So the bottom line is that it does not work because compiler does not
know to which internal boost::function to bound foo, because it could
be bounded to both boost::function<void(int)> and
boost::function<void(std::string)> an "ambiguous call" type error
arise...as it should, if I can dare.

Replying to a previous message...

>> This library extension, although flexible and IMHO powerful is notably
>> very simple and small, so I would like to ask if someone is interested
>> to add this code in some way directly to boost.function
>>
>
>While useful, I do not think this library belongs in boost function (which is monomorphic),
> but it should be a library of its own.

Form boost.function documentation:

"Generally, any place in which a function pointer would be used to
defer a call or make a callback, Boost.Function can be used instead"

Where boost.function naturally models a function, multi-signature
boost::function naturally models an overload set

In the examples there is the implementation of an object factory that
comes out nice and small using MSF. Why? Essentially it boils down to
the fact that class constructors are an overload set!

I can use boost::function to bound to an object member function, say
foo, but if there exist more then one member named foo and I want to
bound them all I have to use different named boost::functions, this is
not a natural extension.

With MSF I model naturally this case because with a single named MSF
object I model all the single named foo members of my object.

So the bottom line here is: "Where boost.function naturally models a
function, multi-signature boost.function naturally models a set of
same named functions"

Thanks
Marco


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