digitalmars.D - overloading by constness
- downs <default_357-line yahoo.de> Jul 24 2007
- Christian Kamm <kamm.incasoftware shift-at-left-and-remove-this.de> Jul 24 2007
- downs <default_357-line yahoo.de> Jul 24 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? In a related question: Will constness ever be part of the name mangling? I realize D 2.0 is still alpha (although one wouldn't suspect that from the way the D homepage looks), so I don't expect it immediately, but some estimate would be nice. I have some code that depends on this. --downs
Jul 24 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
Jul 24 2007
Christian Kamm wrote: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
Thanks for answering. --downs
Jul 24 2007








downs <default_357-line yahoo.de>