overloading by constness
Christian Kamm
kamm.incasoftware at shift-at-left-and-remove-this.de
Tue Jul 24 13:44:20 PDT 2007
> This is the one major thing that stops me from switching to D 2.0, and so
> I have to ask: Are there any plans to allow us to overload D functions by
> the constness of their parameters?
Is this what you mean? Since const() and invariant() construct new types,
overloading should work just fine.
----
void foo(char[] str)
{ writefln("plain"); }
void foo(const(char[]) str)
{ writefln("const"); }
void main()
{
char[] plainstr = "abc".dup;
const(char[]) conststr = "abc";
foo(plainstr); // prints plain
foo(conststr); // prints const
}
----
Christian
More information about the Digitalmars-d
mailing list