Template overloading

Oliver ruebenko at imtek.de
Mon Sep 17 03:09:19 PDT 2007


Hi everyone,

i would like to overload template functions. The following code shows what i'd like. 

import std.stdio;

void test(T1)(T1 n1) {
    writefln("number: ", n1); }

void test(T2)(T2[] array ) {
    writefln("array: ", array); }


void main () {
    double d1 = 2.1;
    double d2 = 1.2;
    double[] da1 = [d1, d2];

    test(d1);
    test(da1);
}

This fails (to my understanding) because the templates are not specialized enough. Is it possible to specialize the template to either accept an array of numbers (of any type) or a single number (of any type). 

Any comments are appreciated. Thanks


More information about the Digitalmars-d-learn mailing list