question with compile-time reflection

Zhenya zheny at list.ru
Sat Mar 9 06:30:29 PST 2013


Hi!

this code fails with message:NDimensionalArray.doIndex(Array) if 
(is(Array _ : NDimensionalArrayType!(T,s),const(int[]) s)) cannot 
deduce template function from argument types 
!()(int[2u][2u],const(int[]))

Tell me please,am I wrong?
And if yes,what should I change to make it work?

template NDimensionalArrayType(T,alias size)
	if(is(typeof(size) _ : const int[]) && size.length > 0)
{
	static if(size.length > 1)
		alias NDimensionalArrayType!(T,size[1..$])[size[0]] 
NDimensionalArrayType;
	else
		alias T[size[0]] NDimensionalArrayType;
}

struct NDimensionalArray(T,alias size)
{
	private NDimensionalArrayType!(T,size) m_array;
	static ref T doIndex(Array)(Array array,const int[] index) //HERE
		if(is(Array _ : NDimensionalArrayType!(T,s),const int[] s))
	{
		assert(index.length == s.length);
		if(index.length == 1)
			return array[index[0]];
		else
			return doIndex(array[index[0]],index[1..$]);
	}
	ref T opIndex(const int[] index)
	{
		return doIndex(m_array,index);
	}
	alias m_array this;
}

void main()
{
	NDimensionalArray!(int,[2,2]) array;
}


More information about the Digitalmars-d-learn mailing list