www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - overloading by constness

reply downs <default_357-line yahoo.de> writes:
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
parent reply Christian Kamm <kamm.incasoftware shift-at-left-and-remove-this.de> writes:
 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
parent downs <default_357-line yahoo.de> writes:
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
Great! Now the only thing I have to wait for is GDC on 2.0 :D Thanks for answering. --downs
Jul 24 2007