Re: opCast using in template struct

2012-12-08 Thread Ali Çehreli
On 10/19/2012 06:38 AM, Oleg wrote: > Problem solved partially. > > http://dpaste.dzfl.pl/e7871a01 > > in structs I use fix length arrays declarations, and alias its to > structs, but not allowed casting to fix length arrays. > I want check array length in compile time > > auto opBinary(string op,

Re: opCast using in template struct

2012-10-19 Thread Oleg
Problem solved partially. http://dpaste.dzfl.pl/e7871a01 in structs I use fix length arrays declarations, and alias its to structs, but not allowed casting to fix length arrays. I want check array length in compile time auto opBinary(string op,E)( E[DLen] b ) // fix length array i

Re: opCast using in template struct

2012-10-18 Thread Era Scarecrow
On Thursday, 18 October 2012 at 23:51:44 UTC, Timon Gehr wrote: If the issue _is_ with the signature, then the compiler should tell you. That is the (secondary) job of the compiler. But not everything is parsed/compiled if it doesn't match the constraints, especially template functions. Somet

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 02:12 AM, bearophile wrote: Timon Gehr: What situations? This thread has already shown two possible cases worth discussing about. This report shows two more cases: http://d.puremagic.com/issues/show_bug.cgi?id=8844 How is that bug-prone? Are there keyboards where : and = are

Re: opCast using in template struct

2012-10-18 Thread bearophile
Timon Gehr: What situations? This thread has already shown two possible cases worth discussing about. This report shows two more cases: http://d.puremagic.com/issues/show_bug.cgi?id=8844 Two more cases: Foo opBinary(string op="/\")(Foo f) {} Foo opBinary(string op)(Foo f) if (op == "@") {

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:23 AM, bearophile wrote: Era Scarecrow: Maybe.. A general warning when something starts with 'op(Op)?[A-Z]' but doesn't actually qualify as any of the override-able operators? That seems sensible... Regarding operator overloading there are several situations worth warning th

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:05 AM, Era Scarecrow wrote: On Thursday, 18 October 2012 at 22:07:55 UTC, Timon Gehr wrote: On 10/18/2012 11:45 PM, bearophile wrote: There are other cases. Generally the D compiler should add some warnings that help against operator overloading mistakes. I don't think that o

Re: opCast using in template struct

2012-10-18 Thread bearophile
Era Scarecrow: Maybe.. A general warning when something starts with 'op(Op)?[A-Z]' but doesn't actually qualify as any of the override-able operators? That seems sensible... Regarding operator overloading there are several situations worth warning the programmer of. The D compilers should b

Re: opCast using in template struct

2012-10-18 Thread Era Scarecrow
On Thursday, 18 October 2012 at 22:07:55 UTC, Timon Gehr wrote: On 10/18/2012 11:45 PM, bearophile wrote: There are other cases. Generally the D compiler should add some warnings that help against operator overloading mistakes. I don't think that operator overloading gives rise to distinct mi

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/18/2012 11:45 PM, bearophile wrote: Era Scarecrow: It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined. This would have to be implemented very carefully. There are enough hard to reproduce symbol resolution

Re: opCast using in template struct

2012-10-18 Thread bearophile
Era Scarecrow: It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined. If you have strong feelings about this, then add a Bugzilla entry. There are other cases. Generally the D compiler should add some warnings that

Re: opCast using in template struct

2012-10-18 Thread Era Scarecrow
On Thursday, 18 October 2012 at 18:12:49 UTC, Simen Kjaeraas wrote: I see you have opOpBinary there - should those be opOpAssign? Probably. It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined.

Re: opCast using in template struct

2012-10-18 Thread Simen Kjaeraas
On 2012-10-18, 17:45, Oleg wrote: Sorry. My problem more complex and my simplification is not correct. I want use mixin for math operations. mixin template vectOp( string DataName, int DataLen, T, vecType ) { mixin( "alias " ~ DataName ~ " this;" ); auto opBinary(string op,E)( E[

Re: opCast using in template struct

2012-10-18 Thread Oleg
Sorry. My problem more complex and my simplification is not correct. I want use mixin for math operations. mixin template vectOp( string DataName, int DataLen, T, vecType ) { mixin( "alias " ~ DataName ~ " this;" ); auto opBinary(string op,E)( E[DataLen] b ) auto opBinary(s

Re: opCast using in template struct

2012-10-18 Thread Simen Kjaeraas
On 2012-10-18, 16:54, Oleg wrote: Hello. How to cast template struct to itself? struct vec(string S,T=double) { T[S.length] data; auto opCast(string K,E)() if( S.length == K.length && is( T : E ) ) { vec!(K,E) ret; foreach( i, ref m; ret.d

opCast using in template struct

2012-10-18 Thread Oleg
Hello. How to cast template struct to itself? struct vec(string S,T=double) { T[S.length] data; auto opCast(string K,E)() if( S.length == K.length && is( T : E ) ) { vec!(K,E) ret; foreach( i, ref m; ret.data ) m = data[i]; retu