From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-05-13 02:50:46
On Mon, May 12, 2008 at 6:39 PM, Giovanni Piero Deretta
> > I have written fast, probably there is a better way, but just to show
> > the idea. Is this what you mean ?
> Not sure if the code would compile, but, yes, that would be the idea,
> except for the fact that in my ideal world
> MSF would have single copy of F.
I was able to implemented in my private trunk the recursive
assignment, called set_all() in a much simpler way than the above, due
to how MSF is structured. Indeed the set_all() code ends up to a
couple of very trivial lines:
void set_all(Fun const& fun)
boost_fun = fun;
If you want I can send you the new msf.zip code directly, or do you
prefer I update the Vault file ? msf-1.0 -> msf-1.1 ?
BTW also the problem of extra copy of boost::function is fixed.
> > > I think that in your case, using
> > > operator= is confusing because you are not really reassigning the MSF but
> > > just adding an overload. What if operator= tries to bind all signatures at
> > > once (and thus allows for boost::function like adaptability) and operator+=
> > > (or an explicit add member function) is strict and allows to replace a single
> > > overload?
> > operator+= is a nice idea, like an explicit set() or add() method. I
> > have been stick to operator=() just to follow boost::function API, but
> > I agree in case of MSF this could be confusing...
> Well, in boost::function, operator= replaces the content of the
> function, which is
> not true in MSF case.
In MSF it's true only for functions with same signature:
f = foo1;
f('x'); // foo1 is called
f = foo2; // foo2 overwrites foo1 as does boost.function
f('x'); // now foo2 is called
>Operator+= might qualify as operator abuse, so
> an explicit
> set or add would be better (but personally have no strong opinion on this)
Well set() is already implemented and it works also with the msf code
you (probably) have downloaded. It is just that is not a documented
API. This is because boost.function that used to have set(), has
discouraged and then removed that API.
BTW MSF implementation _really_ needs set() and not only operator=(),
because for SFINAE to work I need an additional (hidden) argument for
each assignment call. Indeed if you look at overload.hpp, operator=()
implementation is just:
function& operator=(Fun const& f)
And set() is a public method so it is usable directly by the user.
> Not sure of what you cannot parse, so I'll try to be as explicitly as possible.
Thanks for your explanation, I will comment on this in a separated e-mail
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk