Static override?

Atila Neves atila.neves at gmail.com
Sat Apr 5 05:43:11 PDT 2014


That works too. I think I like the solution above better for now,
I just have to figure out how to generalise it into a template
mixin so I don't have to write it out over and over again.

Atila

On Friday, 4 April 2014 at 14:24:55 UTC, Dicebot wrote:
> 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