To use opDispatch

Simen kjaeraas simen.kjaras at gmail.com
Sun May 23 12:13:39 PDT 2010


bearophile <bearophileHUGS at lycos.com> wrote:

> I have seen this bug report:
> http://d.puremagic.com/issues/show_bug.cgi?id=4224
>
> Do you know any way to make the following code work? It can be useful,
> especially once the int type can be replaced with a good variant type:
>

struct A {
   int[string] table;

   auto opDispatch( string name, T... )( T args ) {
     static if ( T.length == 0 ) {
       return table[s];
     } else if ( T.length == 1 ) {
       table[ name ] = args[0];
     } else {
       static assert( false, "Wrong parameter count to opDispatch" );
     }
   }
}

You could factor out the static ifs to template constraints, if you
wish.

-- 
Simen


More information about the Digitalmars-d mailing list