Re: [boost] library for type erasure

AMDG Alexander, This method seems to cover everything I can think of that is actually possible: struct plus : function<plus, anyT (anyT const&, anyT const&)> { template<class R, class T0, class T1> R entry(const T0& t0, const T1& t1) { return(t0 + t1); } } template<> struct overload<plus, int> { typedef typename transform< integral_types, binary_function<promotion_traits<int, _1>, int, _1> >::type type; } //other integral types are similar template<> struct overload<plus, string> { typedef vector< string(const string&, const string&), string(const string&, const char*), string(const char*, const string&) > type; }; This allows new types to be added without changing plus at all. It should be fast since in most cases there will not be a lot of possible overloads after the initial lookup. There would of course be a catch-all when none of the overloads matches. By default it should probably be something like: void no_match(const any<L>& any0, const any<L>& any1) { throw(undefined_function(typeid(plus), any0.type(), any1.type())); } I haven't thought of any real disadvantages to this approach. But, as I haven't tried to implement it yet, I may have missed something. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
Alexander,
This method seems to cover everything I can think of that is actually possible:
struct plus : function<plus, anyT (anyT const&, anyT const&)> { template<class R, class T0, class T1> R entry(const T0& t0, const T1& t1) { return(t0 + t1); } }
template<> struct overload<plus, int> { typedef typename transform< integral_types, binary_function<promotion_traits<int, _1>, int, _1> >::type type; }
//other integral types are similar
template<> struct overload<plus, string> { typedef vector< string(const string&, const string&), string(const string&, const char*), string(const char*, const string&) > type; };
I don't understand how you iterate over all specializations of overload template. -- Alexander Nasonov Project Manager at Akmosoft ( http://www.akmosoft.com ) Blog: http://nasonov.blogspot.com Email: $(FirstName) dot $(LastName) at gmail dot com
participants (2)
-
Alexander Nasonov
-
Steven Watanabe