Clay language

Steven Schveighoffer schveiguy at yahoo.com
Thu Dec 30 08:10:23 PST 2010


On Thu, 30 Dec 2010 11:02:43 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 12/30/10 9:22 AM, Michel Fortin wrote:
>> I stubbled upon this yesterday:
>>
>> Template This Parameters
>>
>> TemplateThisParameters are used in member function templates to pick up
>> the type of the this reference.
>> import std.stdio;
>>
>> struct S
>> {
>> const void foo(this T)(int i)
>> {
>> writeln(typeid(T));
>> }
>> }
>>
>> <http://www.digitalmars.com/d/2.0/template.html>
>>
>> Looks like you could return the type of this this way...
>
> typeof(this) works too.

Nope.  the template this parameter assumes the type of 'this' at the call  
site, not at declaration.  typeof(this) means the type at declaration time.

-Steve


More information about the Digitalmars-d mailing list