simple template constraint - compile error.

WhatMeWorry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 7 21:54:59 PDT 2015


Just a recap. Here's the final fix.  Thanks to Anonymous and Adam.


int arrayByteSize(T)(T someArray) if (isDynamicArray!(T))
{
     ubyte[] arr = cast(ubyte[]) someArray;
     return arr.length;
}

float[] dynamicArray = [1.1, 3.0, 1.0, 7.3];
sizeInBytes = arrayByteSize(dynamicArray);
lengthInElements = dynamicVerts.length;
myLog!dynamicArray;
myLog!lengthInElements;
myLog!sizeInBytes;


dynamicArray = [1.1, 3, 1, 7.3]
lengthInElements = 6
sizeInBytes = 16

And

float[3] staticArray = [3.0, 2.0, 1.0];
sizeInBytes = arrayByteSize(staticArray);  // Does not Compile!


More information about the Digitalmars-d-learn mailing list