Passing a generic struct as parameter

Zardoz luis.panadero at gmail.com
Thu Jun 30 16:39:53 PDT 2011


I have a parametrized struct (Vector!(T, dim)) that takes two parameters 
(Type and a number). And made some Alias with defaults parameters.

In other struct (Matrix!(T, dim)), that uses these struct to represent a 
matrix in column-major order. I have a internall alias for Vector using 
internally (alias Vector!(T,dim_) VCol;) . The problem that I have it's 
when I try to use opIndexAssign to assign to a column a Vector. I try 
this :

void opIndexAssign(Vector v, size_t j) {
	if ( code that see if VCol if same type that v ) {
		col[j] = v;
	} else {
		col[j] = cast (VCol) v;
	}
}

But not compile... I get this error :
Error: struct zmath.vector.Vector(T,ulong dim_) if (__traits
(isFloating,T)) is used as a type
Error: template instance zmath.matrix.Matrix!(float,2) error instantiating

So finally I try this :
/**
* Assigns a new column vector
*/
void opIndexAssign(VCol v, size_t j) {
	col[j] = v;
}

But now I must do cast outside, even knowing that are same type. Plus now 
I must keep VCol alias public.

How should fix this, or What is the correct way of doing this ?


Note : I have a opCast for Vector that cast between Vectors with 
different parameters and it's checked that works.

Second Question : I'm thinking publish this small Vector/Quaternion/
Matrix lib that I made learning D2.. where I should put and how ? (and I 
use Git)

-- 
Yep, I'm afraid that I have a blog : zardoz.es


More information about the Digitalmars-d-learn mailing list