overloading by constness

downs default_357-line at yahoo.de
Tue Jul 24 14:39:35 PDT 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
Great! Now the only thing I have to wait for is GDC on 2.0 :D
Thanks for answering.
  --downs



More information about the Digitalmars-d mailing list