Regarding fixed size arrays

Meta jared771 at gmail.com
Fri Mar 14 18:14:00 PDT 2014


On Saturday, 15 March 2014 at 00:11:22 UTC, bearophile wrote:
> Do you think it's useful/worth supporting code like that?

Yes, I'm surprised that doesn't currently work. I hate how static 
arrays throw away their length at the drop of a hat. In the 
meantime, here's a workaround:

T[N + M] concat(T, int N, int M)(T[N] arr1, T[M] arr2)
{
	T[N + M] result = arr1 ~ arr2;
	
	return result;
}

void main()
{
	int[3] arr1;
	int[2] arr2;
	int[5] arr3 = concat(arr1, arr2);

         //Error: array length mismatch
         int[6] arr4 = concat(arr1, arr2);
}



More information about the Digitalmars-d-learn mailing list