opCast using in template struct
Oleg
code.viator at gmail.com
Fri Oct 19 06:38:00 PDT 2012
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
if( ( op == "+" || op == "-" ) && is( E : T ) )
{
// without this checking in runtime
//if( DLen != b.length )
// throw new Exception("bad length");
auto res = VecT(this);
foreach( i, ref m; mixin( "res." ~ DName ) )
mixin( "m " ~ op ~ "= b[i];" );
return res;
}
if I write E[DLen] I have errors like this
Error: template
opop.vec!("xyz").vec.arrayMath!("data",3LU,double,vec!("xyz")).opAssign
does not match any function template declaration
Error: template
opop.vec!("xyz").vec.arrayMath!("data",3LU,double,vec!("xyz")).opAssign(E)
if (is(E : T)) cannot deduce template function from argument
types !()(int[])
but declaration like this allowed
int[4] f = [1,2,3,4];
also checked in compile time assigning like this
int[4] f;
int[5] g;
g = f; // -> Error: mismatched array lengths, 5 and 4
I think in my situation checking in compile time must be
possibly, because all of template params known in compile time,
but I unknown how to use it...
More information about the Digitalmars-d-learn
mailing list