TypeFunction example creatiing a conversion matrix

Adam D. Ruppe destructionator at gmail.com
Fri Oct 2 03:36:32 UTC 2020


On Friday, 2 October 2020 at 02:23:25 UTC, Andrei Alexandrescu 
wrote:
> Is this a visitation/double dispatch?

ummmm I'm actually not sure. I thought about doing a proper 
double dispatch but instead the implementation is pretty much 
single... just there is a dynamic cast in the convert methods so 
maybe technically it still falls under the definition.

The basic idea though is it doesn't take magic to do this. All 
the types the Variant needs *are* available to it thanks to 
normal templates, every type it ever sees are sent in (and ones 
it never sees it never needs), just the difficulty is they come 
in two separate calls. Thus it extracts what it needs from them 
into a runtime class to bridge that gap. And then any 
compile-time reflection that requires two types simultaneously 
(like `is(a:b)`) will need to have its logic re-implemented in 
library code instead of leveraging the compiler's built in magic. 
That is a legit hassle but not a fatal barrier.

All the runtime data required can be generated by normal 
templates though normal reflection into normal objects of normal 
data. Nothing special required.


More information about the Digitalmars-d mailing list