Template overloading

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Dec 5 15:58:21 PST 2007


Bill Baxter wrote:
> Does anyone have a really good understanding of the dummy=void hack for 
> making two templates with the same name but different arguments?  Every 
> time I try to use that I end up I just end up randomly adding in 
> dummy=voids here and there till it works.  Is there some rationale for 
> where it should go (end of parameter list? beginning?)?  And what about 
> when you have 3 or more templates you need to differentiate?
> 

What do you mean "3 or more templates you need to differentiate"? Do you 
remember this: 
http://d.puremagic.com/issues/show_bug.cgi?format=multiple&id=337 ?

> Also, am I right in thinking that if you pass any of the "real" template 
> arguments explicitly then suddenly the dummy args must be passed too?
> 

Yes, the dummy hack only works implicitly for IFTI.

> Any advice on best practices in this area?
> 
> My most recent run-in with this was trying to write a matrix multiply 
> template that could take arguments of either Mat!(T),Mat!(T), or 
> Mat!(T),Vec!(T).
> 
> --bb

What exactly are you trying to accomplish? This works:

void mult2(T)(Mat!(T) a, Mat!(T) b) {
	pragma(msg, "Mat, Mat");
}

void mult2(T)(Mat!(T) a, Vec!(T) b) {
	pragma(msg, "Mat, Vec");
}


void main() {
     mult2(new Mat!(int), new Mat!(int));
     mult2(new Mat!(int), new Vec!(int));
}

But that seems too simple a solution, was that you were trying to do?

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D


More information about the Digitalmars-d-learn mailing list