Re: What exactly is the use-case for Template This Parameters?

2013-02-23 Thread Lee Braiden
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 examp

Re: What exactly is the use-case for Template This Parameters?

2013-02-18 Thread Andrej Mitrovic
On 2/19/13, Steven Schveighoffer wrote: > // don't need to redefine addAll Ah, that sheds a big light on this feature actually, thanks.

Re: What exactly is the use-case for Template This Parameters?

2013-02-18 Thread Steven Schveighoffer
On Mon, 18 Feb 2013 17:14:54 -0500, 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.

Re: template this parameters

2011-01-25 Thread Steven Schveighoffer
On Tue, 25 Jan 2011 10:58:18 -0500, Steven Schveighoffer wrote: That seems like a bug, but actually, I'd not trust typeid. typeid is actually a runtime-defined TypeInfo class, which you are calling toString on, which is not telling you exactly what the compiler thinks is the type. I s

Re: template this parameters

2011-01-25 Thread Steven Schveighoffer
On Tue, 25 Jan 2011 10:44:23 -0500, Trass3r wrote: Why do they exist It tells you the exact type of this at the call site. For const struct functions, this will tell you what the actual constness of the variable is. For classes, this may give you the derived or base class or interface

Re: template this parameters

2011-01-25 Thread Simen kjaeraas
Trass3r wrote: Why do they exist and why does typeof(this) strip constness? Template this parameters allow for covariant return types, that's about all the use cases I've found for it. It seems like such a great thing, almost doing automatic overriding of methods in subclasses,

template this parameters

2011-01-25 Thread Trass3r
Why do they exist and why does typeof(this) strip constness? import std.stdio; struct S { const void foo(this T)(int i) { writeln(typeid(T)); } const void bar() { writeln(typeid(typeof(this))); } } void main() { const(S) s; (&s).foo(1); S s2;