OK I have been thinking about this in the meantime (hoping I understood the problem, which you confirmed).
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
(&a) or static_cast (any_cast (&a)) for any. b) You can determine the dynamic type of the object with typeid. Replace this with typeid_of(a) for any.
Yes, I have a detail::virtual_traits<> that handles that sort of
things. For the time being is is undocumented, so I can experiment.
The other difficulty is the mechanism used to match declarations and
definitions. Methods can be overloaded (see example here:
https://github.com/jll63/yomm2/blob/master/examples/matrix.cpp#L51).
Method declarations declare (but do not define) an additional function
that has the same name and parameters as the dispatcher function, plus
an extra one. It returns the matching method, which is fed to
decltype(). That's how times(double, dense_matrix&) is matched with
times(double, virtual_