using this instead of typeof(this)

monarch_dodra monarchdodra at gmail.com
Tue Feb 26 08:57:49 PST 2013


On Tuesday, 26 February 2013 at 16:28:59 UTC, Ivan Kazmenko wrote:
> Hi!
>
> I have recently experimented with ways to express the exact 
> instantiated type of a generic struct, and found that I can in 
> some cases use "this" as that type.
>
> -----
> 	this (ref this) // not a postblit constructor
> 	this (ref this, this f, typeof (this), this, ref this g)
> -----
> Ivan Kazmenko.

There was a discussion about this recently (wasn't it with you?) 
and I believe the conclusion basically boiled down to "bug: 
accepts-wrong".

Neither of those two signatures should compile. The fact that 
they do is a bug.

If they do compile, it's undefined behavior. From there, you 
can't rely on anything.

I think there was a bugzilla entry for it, but I'll have to look 
for it.


More information about the Digitalmars-d-learn mailing list