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
On 2/19/13, Steven Schveighoffer wrote:
> // don't need to redefine addAll
Ah, that sheds a big light on this feature actually, thanks.
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.
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
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
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,
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;