Dispatching on a variant

language_fan foo at bar.com.invalid
Sat Sep 26 13:04:22 PDT 2009


Sat, 26 Sep 2009 18:28:52 +0200, Lutger thusly wrote:

> a hash literal works like this, index with the typeid to get a function
> ptr you can call:
> 
> Algebraic!(int, Foo) a;
> a = 3;
> [ typeid(int) : function { writeln("a is int"); },
>   typeid(Foo) : function { writeln("a is Foo"); }
> ] [a.type] ();

A visitor approach might have a bit slower coefficient than the hash, but 
the same time complexity.



More information about the Digitalmars-d mailing list