Static override?

Dicebot public at dicebot.lv
Fri Apr 4 07:24:54 PDT 2014


On Friday, 4 April 2014 at 09:22:16 UTC, Atila Neves wrote:
>     enum hasAccept(T) = is(typeof(() {
>         auto s = T();
>         auto foo = FooVisitor();
>         s.accept(foo);
>         auto bar = BarVisitor();
>         s.accept(bar);
>     }));

I have lately started to favor separated asserts as opposed to 
combined constraints:

mixin template hasAccept(T)
{
     static assert (
         is(typeof(() { auto s = T(); })),
         "Can't create instance of " ~ T.stringof
     );
     static assert (
         is(typeof(FooVisitor)),
         "FooVisitor is not defined"
     );

     // .. and so on
}

It is much less elegant and does not fix issue fundamentally but 
speeds up debugging for end user of the library quite a lot.


More information about the Digitalmars-d mailing list