That gives me this:
static_override.d(22): Error: variable static_override.Struct.hasAccept!(Struct).hasAccept had semantic errors when compiling

Which is better than before but still hiding the actuall error. But this works as expected:

    template hasAccept(T) {
        static iface(CT)(CT t) {
            auto foo = FooVisitor();
            t.accept(foo);
            auto bar = BarVisitor();
            t.accept(bar);
        }
        static if (is(typeof(iface!T)))
            enum hasAccept = true;
        else {
            private static void func() {
                iface(T());
            }
        }
    }

Atila

On Friday, 4 April 2014 at 10:55:53 UTC, Artur Skawina wrote:
On 04/04/14 11:22, Atila Neves wrote:
    enum hasAccept(T) = is(typeof(() {
        auto s = T();
        auto foo = FooVisitor();
        s.accept(foo);
        auto bar = BarVisitor();
        s.accept(bar);
    }));

The static asserts are there to verify that the structs I define actually do implement the interface I want them to. Which is great when they work, but tricky to find out why they don't when the assert fails.

    template hasAccept(T) {
       static iface(CT)(CT t) {
          auto foo = FooVisitor();
          t.accept(foo);
          auto bar = BarVisitor();
          t.accept(bar);
       }
       static if (is(typeof(iface!T)))
          enum hasAccept = true;
       else
          enum hasAccept = &iface!T;
    }

[Should probably be split into three parts: 1) the if-definition, 2) the does-T-implement-the-if check, and 3) the T-must-implement-the-if assertion.]

artur

Reply via email to