scaling of templates with alias argument

Frank Benoit keinfarbton at googlemail.com
Mon May 14 15:22:29 PDT 2007


Stephen Waits schrieb:
> The compiler should only instance each template once per type per
> compilation unit.  The linker should be able to remove duplicates across
> multiple compilation units.

Ok, 'should' is said twice :)

If i have this program:

void regMember( alias T )(){
   // use T.offsetof
   // use T.stringof
}

class MyClass {
    bool     data1;
    bool     data2;
    bool     data3;
    bool     data4;
    public void describe(){
        regMember!(data1);
        regMember!(data2);
        regMember!(data3);
        regMember!(data4);
    }

}
void main(){
}

compiled with:
dmd -c -g refl.d

and then doing this:
obj2asm refl.o | gvim -

This show 4 different functions containing "regMember" in their name,
and four different function calls, matching exactly those 4 different
functions.

The function name differ in the "data1" "data2" .. identifier. This is
not a surprise, because the template argument is not simply a "T", it is
"alias T", which enables me to get the external-scope names.

So i am not sure, if a different type instance in the template argument,
does not also enforce a complete new template instance.

How can i check this?








More information about the Digitalmars-d mailing list