equivariant functions ('in' = headconst!?)
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sat Oct 18 11:45:59 PDT 2008
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.
--
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