February 23, 2013 Re: What exactly is the use-case for Template This Parameters? | ||||
---|---|---|---|---|
| ||||
On Mon, 18 Feb 2013 23:14:54 +0100, Andrej Mitrovic wrote: > http://dlang.org/template.html#TemplateThisParameter > > That's hardly a descriptive example, so in what context is the feature useful? Some code snippets would be welcome so we can update the page with a nicer and more useful example. I guess it's for doing things like: import std.stdio; class Mammal { void printDescription(this T)() { writeln(typeid(T)); } }; void main(string[] args) { class Dog : Mammal {}; class Cat : Mammal {}; auto a = new Dog(); auto b = new Cat(); a.printDescription(); b.printDescription(); } Outputs: hello.main.Dog hello.main.Cat -- Lee |
Copyright © 1999-2021 by the D Language Foundation