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);
lengthInEle
On Monday, 8 June 2015 at 04:02:26 UTC, WhatMeWorry wrote:
On Sunday, 7 June 2015 at 23:13:14 UTC, anonymous wrote:
On Sunday, 7 June 2015 at 23:08:02 UTC, WhatMeWorry wrote:
However, when I try to add a simple constraint to the
function like so:
int arrayByteSize(T)(T[] someArray) if (isDyna
On Monday, 8 June 2015 at 04:02:26 UTC, WhatMeWorry wrote:
Why would a working function call stop working just because a
constraint was added to the function?
because T is float... which isn't a dynamic array, so the
constraint doesn't match. Just remove the [] after T[] in your
signature and
On Sunday, 7 June 2015 at 23:13:14 UTC, anonymous wrote:
On Sunday, 7 June 2015 at 23:08:02 UTC, WhatMeWorry wrote:
However, when I try to add a simple constraint to the function
like so:
int arrayByteSize(T)(T[] someArray) if (isDynamicArray(T))
You forgot an exclamation mark here. Make tha
On Sunday, 7 June 2015 at 23:13:14 UTC, anonymous wrote:
int arrayByteSize(T)(T[] someArray) if (isDynamicArray(T))
You forgot an exclamation mark here. Make that:
isDynamicArray!(T)
Also, if you pass int[] to that function, for example, T will
*not* be int[] - it will actually be int.
(T
On Sunday, 7 June 2015 at 23:08:02 UTC, WhatMeWorry wrote:
However, when I try to add a simple constraint to the function
like so:
int arrayByteSize(T)(T[] someArray) if (isDynamicArray(T))
You forgot an exclamation mark here. Make that: isDynamicArray!(T)
Should be real simple. But adding a small template constraint
causes compile failure. I've got the following working code:
int arrayByteSize(T)(T[] someArray)
{
ubyte[] arr = cast(ubyte[]) someArray;
return arr.length;// length is implicitly converted
to bytes.
}
// running t