Expression templates in D1

SiegeLord none at none.com
Fri Apr 22 16:57:09 PDT 2011


I have been trying to create some simple expression templates in D1 but I've run into trouble. Here is a reduced test case:

class A
{
    void opSub_r(T:int)(T a)
    {
        
    }
    
    void opSub(T)(T a)
    {
        
    }
}

void main(char[][] args)
{  
    A a;
    a - 1;
    a - a; // line 20
    1 - a;
}

The error is:

test.d(20): Error: template test.A.opSub_r(T : int) does not match any function template declaration
test.d(20): Error: template test.A.opSub_r(T : int) cannot deduce template function from argument types !()(A)

My goal is to adjust the code such that the three expressions in the main function all compile. Both opSub's must be templated functions (as far as I can tell) so that the expression templates can work properly. Here is my full code, incidentally:

http://ideone.com/2vZdN

Any ideas of any workabouts? Has anyone done expression templates in D1 and got them to work?

And yes... the code above works fine in D2, but I want to try to get it to work in D1 for now.

Thanks,

-SiegeLord



More information about the Digitalmars-d-learn mailing list