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 that: isDynamicArray!(T)

Thanks, but I still can't get out of the woods. I've distilled
everything down to the following:

------------------------------------------------------------------

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

int i = arrayByteSize(dynamicArray); // works with above function.

------------------------------------------------------------------

However, if I just add a constraint to the function template

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

int i = arrayByteSize(dynamicArray); // Same call - all hell breaks loose.

Error arrayByteSize(T)(T[] someArray) if (isDynamicArray!T)
Error: template compilelinkshaders.arrayByteSize cannot deduce function from argument types !()(float[]), candidates are:

Why would a working function call stop working just because a constraint was added to the function?







Reply via email to