Expression templates in D1

2011-04-22 Thread SiegeLord
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



struct opEquals

2011-03-09 Thread SiegeLord
1) Why does this code not work (dmd 2.051) and how do I fix it:

struct S
{
static S New()
{
S s;
return s;
}

const bool opEquals(ref const(S) s)
{
return true;
}
}

void main()
{
S s;
assert(s == S.New);
}

2) Why is the type of struct opEquals have to be const bool opEquals(ref 
const(T) s)? Why is it even enforced to be anything in particular (it's not 
like there's an Object or something to inherit from)?

-SiegeLord


Re: struct opEquals

2011-03-09 Thread SiegeLord
Steven Schveighoffer Wrote:

 It's a mis-designed feature of structs.  There is a bug report on it:
 
 http://d.puremagic.com/issues/show_bug.cgi?id=3659

It worked fine in D1. Or did you mean that the mis-designed feature is the 
const system?

Anyway, thanks for the link to the bug report. I'll work around it for now.

-SiegeLord

 
 -Steve