Re: [boost] library for type erasure

AMDG Alexander,
For the latter I'm thinking of the following approach:
struct plus : function<plus, anyT (anyT const&, anyT const&)> { int entry(id<1>, int, int) const; double entry(id<2>, double, int) const; // ... std::string entry(id<100>, std::string const&, char) const; // ... };
How do you detect the end of the entries? I can't think of anything better in general but here are some other possibilities that might be more convenient: struct plus : function<plus, anyT (anyT const&, anyT const&)> { typedef boost::mpl::vector< int (int, int), double (double, int), //... string (string const&, char), //... > entry_functions; template<class T, class U> T entry(T t, U u) const; }; or this: struct plus : function<plus, anyT (anyT const&, anyT const&)> { typedef boost::mpl::vector<int, double, string const&> first_any_argument_types; typedef boost::mpl::vector<int, char> second_any_argument_types; template<class T, class U> T entry(T t, U u) const; }; Of course this one only works when you want every possible combination of the types. In any case I agree that there should be a backup to use if the types passed in don't match one of the signatures provided. Maybe something like allowing any one of the arguments to be unbounded. typedef boost::mpl::vector_c<int, 1, 2> possibly_unbounded_any_arg_indexes; Another way would be to require all the types to be the same when at least one of them doesn't match. In Christ, Steven Watanabe

Steven Watanabe wrote:
How do you detect the end of the entries?
http://tinyurl.com/omttl IIRC VC7/VC8 could not compile it. Even if I specified max id manually, I could not compile the library. I stoped development because of this :(
I can't think of anything better in general but here are some other possibilities that might be more convenient:
struct plus : function<plus, anyT (anyT const&, anyT const&)> { typedef boost::mpl::vector< int (int, int), double (double, int), //... string (string const&, char), //... > entry_functions;
template<class T, class U> T entry(T t, U u) const; };
It's limited to 50 entries in default boost configuration.
or this:
struct plus : function<plus, anyT (anyT const&, anyT const&)> { typedef boost::mpl::vector<int, double, string const&> first_any_argument_types; typedef boost::mpl::vector<int, char> second_any_argument_types;
template<class T, class U> T entry(T t, U u) const; };
Of course this one only works when you want every possible combination of the types.
Lets not forget that it's not a variant type. There should a possibility to add default handler.
In any case I agree that there should be a backup to use if the types passed in don't match one of the signatures provided. Maybe something like allowing any one of the arguments to be unbounded.
I like the idea of unbound agrument. We explored several approaches. It makes sense not to tie to one base class. I'll try to find time to think about it. -- 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