Unusual template specialisation behavior

Matthias Walter walter at mail.math.uni-magdeburg.de
Fri Feb 8 04:35:32 PST 2008


Hello guys,

Here's a (minimal) code snippet for my problem:

| struct Expression (R, E) { }
| 
| struct ResolveReference (T)
| {
|     alias T reference_type;
| }
| 
| struct ResolveReference (T : Expression !(R, E))
| {
|     alias T* reference_type;
| }
| 
| void printRefType (T) ()
| {
|     Stdout (ResolveReference !(Expression !(T, T)).reference_type.stringof).newline;
| }
| 
int main (char[][] args)
| {
|     printRefType !(uint);
|     printRefType !(int);
|     printRefType !(long);
|     printRefType !(char);
|     printRefType !(float);
| 
|     return 0;
| }

The output is:

| Expression!(uint,uint) 
| Expression!(int,int) *
| Expression!(long,long) 
| Expression!(char,char) 
| Expression!(float,float) 

If my understanding of template specialisation is correct, only the second call instanciates the template "ResolveReference (T : Expression !(R, E))" and the other ones choose "ResolveReference (T)". Why does this happen only for ints?

My intended behavior would be, that ResolveReference.reference_type is T*, if T is an Expression and T if not. Thus, I expected, that this code returns 

| Expression!(uint,uint) *
| Expression!(int,int) *
| Expression!(long,long) * 
| Expression!(char,char) *
| Expression!(float,float) *

btw, this is tested on Linux, Tango rev 3152, Digital Mars D Compiler v1.021.
Hopefully, I did not miss a bug-fix.

best regards
Matthias Walter


More information about the Digitalmars-d-learn mailing list