20 May 09:10
Re: Egg review result
shunsuke <pstade.mb <at> gmail.com>
2008-05-20 07:10:55 GMT
2008-05-20 07:10:55 GMT
Daniel Walker wrote: >> 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! egg::overload makes use of placeholders for argument pattern matching. It doesn't mean any signature. > The difference is that your Egg-based version cannot handle arbitrary > callable objects (builtins as well as function objects). Egg works with result_of protocol, which supports function-pointers. > 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()); BTW, what if `g(_1)` means templated function returning `g` type? > // 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? I'm reading that thread. The motivation and role seems different. For example, struct IfInt { ... }; // a function object type struct Otherwise { ... }; // a function object type /* It is cumbersome to write down something like this: struct F_ { void operator()(int x) { IfInt()(x); }; void operator()(any x) { Otherwise()(x); }; }; */ // Hence, Egg provides a helper to build overloaded function in one shot. static_<result_of_overload<IfInt(int), Otherwise(_)>::type>::type const f = {{}}; // BTW, f is empty. // Now, if type-erasure is needed..., multi_signature_function<void(int), void(double)> msf = f; Egg doesn't touch a job of multi_signature_function. In fact, I've never used anything like multi_signature_function, so, I probably can't advise you. As suggested, I feel container-like behavior is not a job of multi_signature_function, though. Regards, -- -- Shunsuke Sogame _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RSS Feed