|
Boost : |
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2008-05-19 23:01:39
On Mon, May 19, 2008 at 6:52 PM, shunsuke <pstade.mb_at_[hidden]> wrote:
> Daniel Walker wrote:
>> But perhaps more important than the documentation, I think there could
>> be a lot of beneficial synergy between Egg, and the discussions
>> arising from Marco's multi-signature function. Egg is addressing a
>> somewhat higher level problem than the problem of accommodating
>> builtin functions along with polymorphic function objects, but it
>> seems to me that there's still some overlap. For example, how cool
>> would it be if you could defer builtin functions to use them with
>> fusion? With a little work, parts of Egg could feel right at home in a
>> library that offered this sort of functionality. This combination
>> could be much better than just Egg on it's own - strip out some of
>> Egg's less compelling features and fold what's left into a new project
>> with Marco and I - the whole could be greater than the sum of its
>> parts!
>
> Egg experimentally contained a multi-signature function adaptor.
> Here is an example: http://tinyurl.com/68luzd
> It doesn't perform type-erasure, so I'm not sure there is an overlap.
I looked at it briefly and noticed the term overload_set showed up in
your implementation as well. I think this must be a recurring pattern
- some sort of on-fly set of closely related functions differentiated
by their argument types and arity. Also, I noticed we both came up
with a similar way of representing the signatures of polymorphic
function objects using result_of-style signatures with
mpl::placeholders! That has got to be a good sign!
The difference is that your Egg-based version cannot handle arbitrary
callable objects (builtins as well as function objects). Also, I
didn't notice that you have any mechanism for switching out the
overloads - an insertion or assignment operation, something more
set-like than function-like. I'd like to see us move towards something
along the lines of the following, and I think we're getting there.
template<class T>
T f(T t) { return t; }
struct g {
template<class> struct result;
template<class T> struct result<g(T)> {
typedef T type;
};
T operator(T t) { return t; }
};
overload_set<char(char), int(int), g(_1)> h;
h.insert(&f<char>);
// type-erasure bound to int(int)
h.insert(function<int(int)>(g()));
// polymorphic g bound to g(_1)
h.insert(g());
// rebind int(int) to f
h.insert(&f<int>);
// dispatch to the various overloads
h('a');
h(0);
h("foo");
I have a polymorphic_function (well, I have the boilerplate for a
unary version in an attachment on another thread; I'm
Boost.Preprocessor metaprogramming the nary version now.), which takes
care of promoting the builtins and interpreting both
boost::function-style call signatures and result_of-style
"polymorphic" signatures with placeholders. overload_set can be built
on top of it. I'm not sure that your version can help with this
because it seems to be tightly bound to the whole Egg framework.
However, it would be nice if overload_set could work with fusion,
lambda, etc. out-of-the-box, and I believe Egg has ways of doing that.
Could that functionality be made accessible without having the whole
framework piggybacking along? Other thoughts?
Daniel Walker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk