Method overloading without Type2Type
Philippe Sigaud
philippe.sigaud at gmail.com
Tue Apr 26 13:41:57 PDT 2011
On Tue, Apr 26, 2011 at 22:06, Benjamin Thaut <code at benjamin-thaut.de> wrote:
> The Problem with that version is, that the code that is generated looks like
>
> void main(string[] args){
> auto test = new Foo!(int,float,double,short,byte)();
> test.print();
> test.echo!double(double.init);
> test.echo!short(short.init);
> }
>
> If the types that are used, are no simple data types, but rather large
> structs, they are copied on every function call. Thats exactly what I want
> to avoid. The Type2Type template has a size of 0, thats why I'm using that
> in the first place.
In that case, just use echo(U)() { ...}, like this:
import std.stdio;
class Foo(T,R...) : Foo!(R) {
public void print(){
writefln(T.stringof);
super.print();
}
public void echo(U)() {
writefln(U.stringof);
}
}
class Foo(T){
public void print(){
writefln("end: " ~ T.stringof);
}
public void echo(U)() {
writefln(U.stringof);
}
}
void main(string[] args){
auto test = new Foo!(int,float,double,short,byte)();
test.print();
test.echo!double;
test.echo!short;
}
What's your global goal with this construction? What are you trying to achieve?
More information about the Digitalmars-d-learn
mailing list