calling function templates
Jos van Uden
jvu at nospam.nl
Sun Aug 9 02:08:12 PDT 2009
I noticed that I don't always have to use the bang notation for
function templates. I played around with that a little, but got
an error when I used a static array. I think it's because of a
casting problem or wrong type inference... I don't imagine it's
a bug. Just not possible.
module test;
import std.range;
void putNumbers(Range, T)(Range r, T start, T incr) {
T i = start;
while (!r.empty) {
r.put(i); // line 8
i += incr;
}
}
void main() {
int[] arr = new int[20];
putNumbers!(int[])(arr, 0, 3); // dyn array, bang notation
int[] arr2 = new int[20];
putNumbers(arr2, 0, 3); // dyn array, regular notation
int[20] arr3;
putNumbers!(int[])(arr3, 0, 3); // stat array, bang notation
int[20] arr4;
putNumbers(arr4, 0, 3); // ERROR, stat array, regular notation
}
test.d(8): Error: cast(int[])r is not an lvalue
test.d(25): Error: template instance test.putNumbers!(int[20u],int)
error instantiating
More information about the Digitalmars-d-learn
mailing list