equivariant functions ('in' = headconst!?)

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Oct 19 06:14:48 PDT 2008


Bill Baxter wrote:
> On Sun, Oct 19, 2008 at 3:45 AM, Bruno Medeiros
> <brunodomedeiros+spam at com.gmail> wrote:
>> Andrei Alexandrescu wrote:
>>> You'll be glad then to learn that "in" means const at least in D2:
>>>
>>> void foo(in char[] s); // same as foo(const(char)[] s)
>>>
>> What??
>> Whoa, at first I thought you were mistaken, and meant 'const(char[]) s'
>> instead (since that is what is the same as 'const char[] s'), but I fired up
>> my editor and tried it out, and it works as you described! Even more
>> surprising, it works the same way when using a class type:
>>
>> class Foo { int x; }
>>
>> void func(in Foo foo, const scope Foo foo2)
>> {
>>  foo = null; // Ok!
>>  //foo2 = null; //Compile error!
>>  //foo.x = 0;  // Compile error!
>>  pragma(msg, (typeof(foo)).stringof ~ " " ~ (typeof(foo2)).stringof);
>> }
>>
>> Which means 'in' works exactly as headconst! Is this another easter egg, or
>> a bug? It's certainly not according to the spec at least.
> 
> I think you mean "tailconst".  The head is not const, the tail is.
> 
> --bb

Yes, exactly, I meant 'tailconst'.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list