opCast using in template struct
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Oct 18 11:12:31 PDT 2012
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[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]
I see you have opOpBinary there - should those be opOpAssign?
--
Simen
More information about the Digitalmars-d-learn
mailing list