opDispatch(string name, E...) (E e) question.
James Miller
james at aatch.net
Sun Mar 25 14:59:17 PDT 2012
On 26 March 2012 10:34, bls <bizprac at orange.fr> wrote:
>
> (T) (T[] t) AND (T) (T t) seems not to work.
Ok, so looking here: http://dlang.org/function.html, I have determined
that, if you are using Variant arrays (though I'm not sure if you can
do that using literals...) you can use the syntax from this example:
int test() {
return sum(1, 2, 3) + sum(); // returns 6+0
}
int func() {
int[3] ii = [4, 5, 6];
return sum(ii); // returns 15
}
int sum(int[] ar ...) {
int s;
foreach (int x; ar)
s += x;
return s;
}
You'll probably need to do some experimentation to figure out how
Variant fits into that properly, but it shouldn't be too hard.
Also, remember that opDispatch takes the name of the function as the
last parameter, so watch out for that.
--
James Miller
More information about the Digitalmars-d-learn
mailing list