
Mathias Gaunard <mathias.gaunard <at> ens-lyon.org> writes:
Isn't that what apply_visitor already does, albeit it only deals with variant and not base classes?
Not exactly (as far as I understood apply_visitor). The dispatch is a mapping from a call to an interface function (variant, virtual abstract classes, etc) to the appropriate template function doing the job. In the example I provided, the "MyInterface const*" class will be tested for exact matching with the template "real_type const&", while the variants will be tested for convertibility and "back" convertibility at the end of the call (tell me if it is not clear :) ). Plus the call succeeds when all the parameters have been matched. So the first call ("template_function < class_t1 >") succeeds if - "i_class1" (MyInterface const *) can be dynamic_casted to "class_t1 const&", - "param" (variant const&) can be casted to double and - "param_out" (int) can be casted to variant& ("out"). Otherwise the second template function ("template_function < class_t2 >") is tested. The types which are tested for matching are either convertibles and/or exact, depending on the convertor. Currently I have 3 different type of convertors: - compile time: which map for instance an uint8 to a float - dynamic_cast: from a base class to a concrete class - runtime: depending on the content of the object (variant)