digitalmars.D - overloading by constness
- downs (7/7) Jul 24 2007 This is the one major thing that stops me from switching to D 2.0, and s...
- Christian Kamm (17/20) Jul 24 2007 Is this what you mean? Since const() and invariant() construct new types...
- downs (4/30) Jul 24 2007 Great! Now the only thing I have to wait for is GDC on 2.0 :D
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:Great! Now the only thing I have to wait for is GDC on 2.0 :D Thanks for answering. --downsThis 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