
AMDG On 01/19/2018 01:50 PM, Jean-Louis Leroy via Boost wrote:
I have zero experience using TypeErasure so what I am going to say here may miss the point entirely.
A priori it's two different worlds because open methods suppose that there is an is-a relationship between the virtual parameters in the method declaration and the corresponding arguments in the method definitions (aka overrides or specializations). It also supposes that virtual parameters are polymorphic types.
But why exactly do you require it? a) You can do a (static|dynamic)_cast from the base to the derived type. Replace this with any_cast<Derived*>(&a) or static_cast<Derived*>(any_cast<void*>(&a)) for any. b) You can determine the dynamic type of the object with typeid. Replace this with typeid_of(a) for any. Plain boost::any has similar features, although I don't think it supports any_cast<void*>.
But wait! yomm2 supports virtual_<std::shared_ptr<Animal>> parameters in addition to virtual_<Animal&> and virtual_<Animal*> - and shared_ptrs are not polymorphic types (neither is Animal* in fact) so there is some flexibility here.
Do you mean something like (inspired from my synopsis):
Yes, that's exactly what I mean. (Note that if you were to use virtual_<any<typeid_<> >, _self&>>, it would essentially be able to accept anything.)
using AnyAnimal = any< mpl::vector< ... > >;
declare_method(string, kick, (virtual_<AnyAnimal>));
define_method(string, kick, (Dog* dog)) { return "bark"; }
define_method(string, kick, (Bulldog* dog)) { return "bark and bite"; }
...or even (following Steven's Basic Usage example):
using AnyCounter = any< mpl::vector< copy_constructible<>, typeid_<>, incrementable<>, ostreamable<> >
;
declare_method(string, describe, (virtual_<AnyCounter>));
define_method(string, describe, (int* num)) { return "it's an integer"; }
define_method(string, describe, (double* dog)) { return "it's a double"; }
If I'm off the mark maybe you can provide an example to illustrate your question?
In Christ, Steven Watanabe