const challenge

Christopher Wright dhasenan at gmail.com
Sun Feb 3 10:17:01 PST 2008


Walter Bright wrote:
> Janice Caron wrote:
>> Still - nobody here was suggesting unique "on a whim". Rather, it was
>> to solve a class of problems, the most obvious of which is to allow
>> the following to compile:
>>
>>     string s;
>>     char[] t;
>>     char[] u = "hello" ~ s ~ t;
> 
> I understand that's a problem. The solution, however, doesn't need 
> unique. It can be solved by having the result type of ~ be a polysemous 
> type, i.e. its type is based on how it is used.

More simply, catenation of a mutable variable with a non-mutable one 
could yield a mutable one by default. A const cast is safer than a 
non-const cast, after all. One could extend that to all binary 
operators, as well.

This might reduce the usage of const. Walter doesn't seem concerned 
about that, since he ignored just about everyone here when we asked for 
function arguments to be const by default.



More information about the Digitalmars-d mailing list