opDispatch and UFCS

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 11 16:46:48 PDT 2016


struct S
{
     int a;
     template opDispatch(string s)
     {
         template opDispatch(T...)
         {
             auto ref opDispatch(Args ...)(auto ref Args args)
             {
                 return S(mixin(`a.` ~ s ~ (T.length ? `!T` : ``) 
~ `(args)`));
             }
         }
     }
}

int foo(int a, int b)
{
     return a + b;
}

S bar(S s, int b)
{
     return S(s.a - b);
}

unittest
{
     auto s = S(3);
     s = s.bar(1);
     assert(s.a == 2);
     s = s.foo(1);
     assert(s.a == 3);
}

this gives me:

test.d-mixin-10(10): Error: function opdispatchtest.bar (S s, int 
b) is not callable using argument types (int, int)
test.d(29): Error: template instance 
test.S.opDispatch!"bar".opDispatch!().opDispatch!int error 
instantiating

Bug? Or am I misunderstanding how these two features are supposed 
to interact?


More information about the Digitalmars-d-learn mailing list