I'm having difficulty understanding how templates operate as function parameters.

Say I have this:

struct ArrayTest {

        void arrayTest(T) (T arrayT) {

                writeln(arrayT);
        }
}

unittest {

ArrayTest test;

        float farray[] = [
                0.5f,  0.5f, 0.0f,
                0.5f, -0.5f, 0.0f,
                -0.5f, -0.5f, 0.0f,
                -0.5f,  0.5f, 0.0f
        ];

        test.arrayTest(farray);

}

Everything works peachy as expected. But as soon as I add another parameter to the arrayTest function like so (and changing the unit test to match):

void arrayTest(T, int passing) (T arrayT) { ... }

I get 'cannot deduce function from argument types' errors.

Specifically stating the type of the function doesn't seem to help:

test.arrayTest(float [])(farray, 1);

There must be a way to mix template and non-template parameters, right? What am I missing here?

In addition, as I understand it, one can restrict the type of parameter a template can use. So if I only wanted arrays as the function name indicates, I should be able to do this:

void arrayTest(T : T[]) (T arrayT) { ... }

But that also doesn't seem to work.

Reply via email to