opCast using in template struct

Oleg code.viator at gmail.com
Thu Oct 18 08:45:12 PDT 2012


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(string op,E)( E[] b ) ....
     auto opOpBinary(string op,E)( E[] b ) ....
     auto opOpBinary(string op,E)( E[DataLen] b ) ....
....
}

struct vec(string S,T=double)
{
     T[S.length] data;
     mixin vectOp( "data", S.length, T, vec!(S,T) );
}

unittest{
    vec!"xyz" a;
    vec!"xyz" b;
    a += b;
}

and it isn't work

Error: 'a += b' is not a scalar, it is a vec!("xyz")
Error: 'a._data' is not of arithmetic type, it is a double[3LU]
Error: 'b._data' is not of arithmetic type, it is a double[3LU]


More information about the Digitalmars-d-learn mailing list