Re: Access derived type in baseclass static function template
On Wednesday, 2 August 2017 at 15:38:12 UTC, Steven Schveighoffer wrote: On 8/2/17 11:06 AM, Timoses wrote: On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven Schveighoffer wrote: However, your original code has potential as an enhancement request, as the type is known at compile-time and could certainly be resolved to pass in as the `this` template parameter. I guess the `this` is really misleading it being a static method. I suppose https://issues.dlang.org/buglist.cgi?bug_severity=enhancement&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&product=D&query_format=report-table&y_axis_field=bug_severity would be the place for an enhancement request? Possibly related: https://issues.dlang.org/show_bug.cgi?id=14191 Yes, that's exactly it. Note that typeof(this) has special meaning for static methods: class C { static typeof(this) foo() { return new typeof(this); } } So there is precedence for the meaning of `this` in a static context. -Steve Oh, just now get it after creating the issue ^^. Makes sense. I kind of connected the "this" to existing instances because the DMD compiler often complains about something like "need this for..." when calling something from a static method that... well... needs "this" or instantiation.. E.g.: class A { static void a() { b(); } void b(); } will throw Error: need 'this' for 'b' of type 'void()'
Re: Access derived type in baseclass static function template
On Wednesday, 2 August 2017 at 12:07:46 UTC, Timoses wrote: Hey, wondering whether it's possible to access the derived type from a function template in the base class or interface. [...] Created an enhancement issue: https://issues.dlang.org/show_bug.cgi?id=17714
Re: Access derived type in baseclass static function template
On 8/2/17 11:06 AM, Timoses wrote: On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven Schveighoffer wrote: However, your original code has potential as an enhancement request, as the type is known at compile-time and could certainly be resolved to pass in as the `this` template parameter. I guess the `this` is really misleading it being a static method. I suppose https://issues.dlang.org/buglist.cgi?bug_severity=enhancement&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&product=D&query_format=report-table&y_axis_field=bug_severity would be the place for an enhancement request? Possibly related: https://issues.dlang.org/show_bug.cgi?id=14191 Yes, that's exactly it. Note that typeof(this) has special meaning for static methods: class C { static typeof(this) foo() { return new typeof(this); } } So there is precedence for the meaning of `this` in a static context. -Steve
Re: Access derived type in baseclass static function template
Thanks Arafel, the alias workaround might just be a nice way to put it. On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven Schveighoffer wrote: What you are looking for is virtual static methods, and D doesn't have those. I don't know if there's a way to make it work with existing features. I'm not looking to overwrite the static method (which would refer to virtual, right?). The solution I had previously was: interface I { static void test(T)() { writeln(T.stringof); } } class B : I { alias type = int; static void test() { I.test!type(); } } void main() { B.test(); } However, this requires to add the base type as in I.test!type(); otherwise (only test!type();) it complains about Error: template instance test!type test is not a template declaration, it is a function I was hoping there was a way to simply define it in the base class/interface without producing redundant code in each derived class. Arafel's solution gets very close! On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven Schveighoffer wrote: However, your original code has potential as an enhancement request, as the type is known at compile-time and could certainly be resolved to pass in as the `this` template parameter. I guess the `this` is really misleading it being a static method. I suppose https://issues.dlang.org/buglist.cgi?bug_severity=enhancement&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&product=D&query_format=report-table&y_axis_field=bug_severity would be the place for an enhancement request? Possibly related: https://issues.dlang.org/show_bug.cgi?id=14191 On Wednesday, 2 August 2017 at 14:23:26 UTC, Arafel wrote: What you are looking for is virtual static methods, and D doesn't have those. I don't know if there's a way to make it work with existing features. Well, there are interesting things to do: https://dpaste.dzfl.pl/ed826ae21473 I don't know if that's what one would call "virtual static", but I'd say it comes close... Nifty, but still doesn't allow knowing the derived type B in the foo method of A, does it?
Re: Access derived type in baseclass static function template
What you are looking for is virtual static methods, and D doesn't have those. I don't know if there's a way to make it work with existing features. Well, there are interesting things to do: https://dpaste.dzfl.pl/ed826ae21473 I don't know if that's what one would call "virtual static", but I'd say it comes close...
Re: Access derived type in baseclass static function template
On 8/2/17 9:11 AM, Timoses wrote: On Wednesday, 2 August 2017 at 12:49:12 UTC, Steven Schveighoffer wrote: Thanks for the reply! Not sure I understand correctly, though. interface I {} class A : I {} void test(T)(T t) if(is(T: I)) { writeln(T.type.stringof); } void main() { A.test; } throws: Error: no property 'test' for type 'app.A' which it of course does... test(A) makes no sense either. I need to call it statically and want to know the derived class type in the base class (or interface) function template. Is there a trick in your answer? : P Sorry, I didn't read your original post thoroughly, you need an instance to make this work properly. A a; a.test; // should work What you are looking for is virtual static methods, and D doesn't have those. I don't know if there's a way to make it work with existing features. However, your original code has potential as an enhancement request, as the type is known at compile-time and could certainly be resolved to pass in as the `this` template parameter. -Steve
Re: Access derived type in baseclass static function template
On 08/02/2017 02:07 PM, Timoses wrote: Hey, wondering whether it's possible to access the derived type from a function template in the base class or interface. this T does not seem to be working, I guess because it's a static function and this does not exists?! [...] Any way I could accomplish this? Well, it's a clumsy workaround, but the only thing missing seems to be the "this T" automatic deduction. I was recently hit by something similar: the "this" parameter deduction only works for instance methods. It was not totally clear if it was a bug or a feature... The documentation [1] is however quite clear: TemplateThisParameters are used in member function templates to pick up the type of the this reference. So, static functions doesn't seem to be covered. You can, however, make it explicit: ``` B.test!B(); C.test!C(); ``` And then even alias it to prevent accidental mismatches: ``` import std.stdio; interface I { static void test(this T)() { writeln(T.type.stringof); } } abstract class A { static void test(this T)() { writeln(T.type.stringof); } } class B : A { alias type = uint; } class C : I { alias type = int; } void main() { test!B(); test!C(); } alias test(T) = T.test!T; ``` [1]: http://dlang.org/spec/template.html#TemplateThisParameter
Re: Access derived type in baseclass static function template
On Wednesday, 2 August 2017 at 12:49:12 UTC, Steven Schveighoffer wrote: On 8/2/17 8:07 AM, Timoses wrote: Hey, wondering whether it's possible to access the derived type from a function template in the base class or interface. this T does not seem to be working, I guess because it's a static function and this does not exists?! Yep. Any way I could accomplish this? Move test outside the interface: void test(C)(C c) if(is(C : I)) { writeln(C.type.stringof); } Though, at that point, you don't need I. I'm assuming you have a more complex real-world example. -Steve Thanks for the reply! Not sure I understand correctly, though. interface I {} class A : I {} void test(T)(T t) if(is(T: I)) { writeln(T.type.stringof); } void main() { A.test; } throws: Error: no property 'test' for type 'app.A' which it of course does... test(A) makes no sense either. I need to call it statically and want to know the derived class type in the base class (or interface) function template. Is there a trick in your answer? : P
Re: Access derived type in baseclass static function template
On 8/2/17 8:07 AM, Timoses wrote: Hey, wondering whether it's possible to access the derived type from a function template in the base class or interface. this T does not seem to be working, I guess because it's a static function and this does not exists?! Yep. Any way I could accomplish this? Move test outside the interface: void test(C)(C c) if(is(C : I)) { writeln(C.type.stringof); } Though, at that point, you don't need I. I'm assuming you have a more complex real-world example. -Steve
Access derived type in baseclass static function template
Hey, wondering whether it's possible to access the derived type from a function template in the base class or interface. this T does not seem to be working, I guess because it's a static function and this does not exists?! interface I { static void test(this T)() { writeln(T.type.stringof); } } abstract class A { static void test(this T)() { writeln(T.type.stringof); } } class B : A { alias type = uint; } class C : I { alias type = int; } void main() { B.test(); C.test(); } Throws: Error: template app.A.test cannot deduce function from argument types !()(), candidates are: app.A.test(this T)() Error: template app.I.test cannot deduce function from argument types !()(), candidates are: app.I.test(this T)() Any way I could accomplish this?
Re: Static function template
On Thursday, 7 May 2015 at 11:18:17 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:15:02 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák > wrote: >> >> On Thu, 07 May 2015 10:33:44 + >> Vadim Lopatin via Digitalmars-d-learn >> wrote: >> >>> struct S >>> { >>> int i; >>> >>> auto foo2(T)(int j) { >>> i=j; >>> } >>> >>> static S foo(T)(int j) { >>> S s; >>> s.foo2!T(j); >>> return s; >>> } >>> } >>> >>> void main() >>> { >>> auto s = S.foo!bool(1); >>> } >> >> As I said, it is not bug. It is OK. There is no way how >> you can >> distinguish between static and non static methods or even >> field in some >> cases. > > e.g.: > > import std.stdio; > > struct S > { >string foo = "Please select me?"; >string foo() { return ("No, select me?"); }; > static string foo() { return ("I am better than the > otters :D?"); }; > } > > void main() > { >auto s = S(); >writeln(s.foo); > } Well it's clear to me now why it shouldn't work. However, the error msg is not clear on the problem. Imo it should give a conflict error like in your previous example. That would make it clear what's happened/allowed. Yep, I think you are right even this example make useless and wrong error message: struct S { static S foo(T)(int j) { S s; return s; } static S foo(T)(int j) { S s; return s; } } void main() { auto s = S.foo!bool(1); } test.d(15): Error: need 'this' for 'foo' of type '(int j)' // WTF? btw. it is a regresion from 2.067 on 2.066 and before it makes much better error. Even for OP code when is modified (static must be declared before non static one) it have a better error msg. test.d(6): Error: test.S.foo called with argument types (int) matches both: test.d(4): test.S.foo!bool.foo(int j) and: test.d(10): test.S.foo!bool.foo(int j) test.d(18): Error: template instance test.S.foo!bool error instantiating But only when static one is declared before non static one, so even on 2.066 it was not ideal. So I think we should open two issues, probably one for regression and one for enhancment OK both are regressions, cause on dmd 2.063 it is much much better test.d(19): Error: template test.S.foo matches more than one template declaration, test.d(3):foo(T)(int j) and test.d(8):foo(T)(int j) test.d(19): Error: need 'this' for 'foo' of type 'pure nothrow @safe void(int j)' https://issues.dlang.org/show_bug.cgi?id=14554
Re: Static function template
On Thursday, 7 May 2015 at 10:19:44 UTC, Lemonfiend wrote: Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j); return s; } } void main() { auto s = S.foo!bool(1); } Error: need 'this' for 'foo' of type '(int j)' Another thinks which is wierd is than on 2.066 it prints: test.d(17): Error: need 'this' for 'foo' of type 'pure nothrow @nogc @safe void(int j)' So it seems auto deduction for attributes does not work anymore :( (in this case I guess)
Re: Static function template
On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: >> >> On Thu, 07 May 2015 10:33:44 + >> Vadim Lopatin via Digitalmars-d-learn >> wrote: >> >>> struct S >>> { >>> int i; >>> >>> auto foo2(T)(int j) { >>> i=j; >>> } >>> >>> static S foo(T)(int j) { >>> S s; >>> s.foo2!T(j); >>> return s; >>> } >>> } >>> >>> void main() >>> { >>> auto s = S.foo!bool(1); >>> } >> >> As I said, it is not bug. It is OK. There is no way how you >> can >> distinguish between static and non static methods or even >> field in some >> cases. > > e.g.: > > import std.stdio; > > struct S > { >string foo = "Please select me?"; >string foo() { return ("No, select me?"); }; > static string foo() { return ("I am better than the otters > :D?"); }; > } > > void main() > { >auto s = S(); >writeln(s.foo); > } Well it's clear to me now why it shouldn't work. However, the error msg is not clear on the problem. Imo it should give a conflict error like in your previous example. That would make it clear what's happened/allowed. Yep, I think you are right even this example make useless and wrong error message: struct S { static S foo(T)(int j) { S s; return s; } static S foo(T)(int j) { S s; return s; } } void main() { auto s = S.foo!bool(1); } test.d(15): Error: need 'this' for 'foo' of type '(int j)' // WTF? btw. it is a regresion from 2.067 on 2.066 and before it makes much better error. Even for OP code when is modified (static must be declared before non static one) it have a better error msg. test.d(6): Error: test.S.foo called with argument types (int) matches both: test.d(4): test.S.foo!bool.foo(int j) and: test.d(10): test.S.foo!bool.foo(int j) test.d(18): Error: template instance test.S.foo!bool error instantiating But only when static one is declared before non static one, so even on 2.066 it was not ideal. So I think we should open two issues, probably one for regression and one for enhancment
Re: Static function template
On Thursday, 7 May 2015 at 11:15:02 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: >> >> On Thu, 07 May 2015 10:33:44 + >> Vadim Lopatin via Digitalmars-d-learn >> wrote: >> >>> struct S >>> { >>>int i; >>> >>>auto foo2(T)(int j) { >>>i=j; >>>} >>> >>>static S foo(T)(int j) { >>>S s; >>>s.foo2!T(j); >>>return s; >>>} >>> } >>> >>> void main() >>> { >>>auto s = S.foo!bool(1); >>> } >> >> As I said, it is not bug. It is OK. There is no way how >> you can >> distinguish between static and non static methods or even >> field in some >> cases. > > e.g.: > > import std.stdio; > > struct S > { >string foo = "Please select me?"; >string foo() { return ("No, select me?"); }; > static string foo() { return ("I am better than the otters > :D?"); }; > } > > void main() > { >auto s = S(); >writeln(s.foo); > } Well it's clear to me now why it shouldn't work. However, the error msg is not clear on the problem. Imo it should give a conflict error like in your previous example. That would make it clear what's happened/allowed. Yep, I think you are right even this example make useless and wrong error message: struct S { static S foo(T)(int j) { S s; return s; } static S foo(T)(int j) { S s; return s; } } void main() { auto s = S.foo!bool(1); } test.d(15): Error: need 'this' for 'foo' of type '(int j)' // WTF? btw. it is a regresion from 2.067 on 2.066 and before it makes much better error. Even for OP code when is modified (static must be declared before non static one) it have a better error msg. test.d(6): Error: test.S.foo called with argument types (int) matches both: test.d(4): test.S.foo!bool.foo(int j) and: test.d(10): test.S.foo!bool.foo(int j) test.d(18): Error: template instance test.S.foo!bool error instantiating But only when static one is declared before non static one, so even on 2.066 it was not ideal. So I think we should open two issues, probably one for regression and one for enhancment OK both are regressions, cause on dmd 2.063 it is much much better test.d(19): Error: template test.S.foo matches more than one template declaration, test.d(3):foo(T)(int j) and test.d(8):foo(T)(int j) test.d(19): Error: need 'this' for 'foo' of type 'pure nothrow @safe void(int j)'
Re: Static function template
On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: > On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: > >> > >> On Thu, 07 May 2015 10:33:44 + > >> Vadim Lopatin via Digitalmars-d-learn > >> wrote: > >> > >>> struct S > >>> { > >>> int i; > >>> > >>> auto foo2(T)(int j) { > >>> i=j; > >>> } > >>> > >>> static S foo(T)(int j) { > >>> S s; > >>> s.foo2!T(j); > >>> return s; > >>> } > >>> } > >>> > >>> void main() > >>> { > >>> auto s = S.foo!bool(1); > >>> } > >> > >> As I said, it is not bug. It is OK. There is no way how you can > >> distinguish between static and non static methods or even > >> field in some > >> cases. > > > > e.g.: > > > > import std.stdio; > > > > struct S > > { > > string foo = "Please select me?"; > > string foo() { return ("No, select me?"); }; > > static string foo() { return ("I am better than the otters > > :D?"); }; > > } > > > > void main() > > { > > auto s = S(); > > writeln(s.foo); > > } > > Well it's clear to me now why it shouldn't work. > > However, the error msg is not clear on the problem. Imo it should > give a conflict error like in your previous example. That would > make it clear what's happened/allowed. > Yep, I think you are right even this example make useless and wrong error message: struct S { static S foo(T)(int j) { S s; return s; } static S foo(T)(int j) { S s; return s; } } void main() { auto s = S.foo!bool(1); } test.d(15): Error: need 'this' for 'foo' of type '(int j)' // WTF?
Re: Static function template
On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: struct S { int i; auto foo2(T)(int j) { i=j; } static S foo(T)(int j) { S s; s.foo2!T(j); return s; } } void main() { auto s = S.foo!bool(1); } As I said, it is not bug. It is OK. There is no way how you can distinguish between static and non static methods or even field in some cases. e.g.: import std.stdio; struct S { string foo = "Please select me?"; string foo() { return ("No, select me?"); }; static string foo() { return ("I am better than the otters :D?"); }; } void main() { auto s = S(); writeln(s.foo); } Well it's clear to me now why it shouldn't work. However, the error msg is not clear on the problem. Imo it should give a conflict error like in your previous example. That would make it clear what's happened/allowed. The current error seemed like it matched the wrong template, prompting me to look for a buggy function template implementation.
Re: Static function template
On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: struct S { int i; auto foo2(T)(int j) { i=j; } static S foo(T)(int j) { S s; s.foo2!T(j); return s; } } void main() { auto s = S.foo!bool(1); } As I said, it is not bug. It is OK. There is no way how you can distinguish between static and non static methods or even field in some cases. e.g.: import std.stdio; struct S { string foo = "Please select me?"; string foo() { return ("No, select me?"); }; static string foo() { return ("I am better than the otters :D?"); }; } void main() { auto s = S(); writeln(s.foo); }
Re: Static function template
On Thursday, May 07, 2015 10:19:42 Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? No. Unfortunately, you can't overload based on static. I believe that it works if they're overloaded on parameters but not based on static. It's probably in order to avoid function hijacking in cases like this: S s; s.foo(); since unfortunately, that call syntax works whether foo is static or not. I think that it would be much better if you had to call it via the type and that calling via an instance wouldn't be legal, but it is legal. And given that fact, overloading based on static would arguably be a bad idea. - Jonathan M Davis
Re: Static function template
On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: > struct S > { > int i; > > auto foo2(T)(int j) { > i=j; > } > > static S foo(T)(int j) { > S s; > s.foo2!T(j); > return s; > } > } > > void main() > { > auto s = S.foo!bool(1); > } As I said, it is not bug. It is OK. There is no way how you can distinguish between static and non static methods or even field in some cases.
Re: Static function template
On Thu, 07 May 2015 10:19:42 + Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? > > struct S > { > int i; > > auto foo(T)(int j) { > i=j; > } > > static auto foo(T)(int j) { > S s; > s.foo!T(j); > return s; > } > } > > void main() > { > auto s = S.foo!bool(1); > } > > Error: need 'this' for 'foo' of type '(int j)' Btw. you can use s.foo even for static: struct S { int i; static auto foo(T)(int j) { S s; s.i = j; return s; } } void main() { auto s = S(); s = s.foo!bool(1); writeln(s); }
Re: Static function template
On Thursday, 7 May 2015 at 10:19:44 UTC, Lemonfiend wrote: Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j); return s; } } void main() { auto s = S.foo!bool(1); } Error: need 'this' for 'foo' of type '(int j)' Can be fixed by using of different names for static and non-static function. Not sure why doesn't work w/o this change (compiler bug?) struct S { int i; auto foo2(T)(int j) { i=j; } static S foo(T)(int j) { S s; s.foo2!T(j); return s; } } void main() { auto s = S.foo!bool(1); }
Re: Static function template
On Thu, 07 May 2015 10:19:42 + Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? > > struct S > { > int i; > > auto foo(T)(int j) { > i=j; > } > > static auto foo(T)(int j) { > S s; > s.foo!T(j); > return s; > } > } > > void main() > { > auto s = S.foo!bool(1); > } > > Error: need 'this' for 'foo' of type '(int j)' It is not. You can't even have same name for field and method: struct S { int s; void s() { do_something(); } } test.d(8): Error: function test.S.s conflicts with variable test.S.s at test.d(7) And this make sense
Static function template
Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j); return s; } } void main() { auto s = S.foo!bool(1); } Error: need 'this' for 'foo' of type '(int j)'
Re: is there such a thing as a "static" function template that isn't inside of a class?
On 2011-07-16 23:34, Christopher the Magnificent wrote: I see this code AT THE TOP (MODULE) LEVEL of one of Michel Fortin's D/Objective-C bridge source files and I'm trying to wrap my head around it. /** Wrap an object instance within an object of this class. */ static Object objcCreateWrapper(T)(id instance) { // Retain the Objective-C instance prior wrapping it. // It needs to be done prior wrapping so that // invariants holds // after the constructor is called. objc.msg.send!(id)(instance, selector!("retain")); // Create new Wrapper. return new T(instance); } At issues is the keyword "static" in front of the template function. This is not inside of a class, so static does not seem to make sense with what I know about D. Can anyone explain this to me? --Christopher I'm guessing it has no affect on the code, possible it used to be a static method in a class. -- /Jacob Carlborg
is there such a thing as a "static" function template that isn't inside of a class?
I see this code AT THE TOP (MODULE) LEVEL of one of Michel Fortin's D/Objective-C bridge source files and I'm trying to wrap my head around it. /** Wrap an object instance within an object of this class. */ static Object objcCreateWrapper(T)(id instance) { // Retain the Objective-C instance prior wrapping it. // It needs to be done prior wrapping so that // invariants holds // after the constructor is called. objc.msg.send!(id)(instance, selector!("retain")); // Create new Wrapper. return new T(instance); } At issues is the keyword "static" in front of the template function. This is not inside of a class, so static does not seem to make sense with what I know about D. Can anyone explain this to me? --Christopher