Logical const

Steven Schveighoffer schveiguy at yahoo.com
Thu Dec 2 12:37:30 PST 2010


On Thu, 02 Dec 2010 15:25:49 -0500, Don <nospam at nospam.com> wrote:

> Jonathan M Davis wrote:
>> On Thursday, December 02, 2010 01:18:31 Don wrote:
>>> Walter Bright wrote:
>>>> spir wrote:
>>>>> What would be the consequences if D had no const, only immutable
>>>>> (that, IIUC, removes the latter non-guarantee)?
>>>> You'd have to write most every function twice, once to take immutable
>>>> args and again for mutable ones.
>>> Doesn't 'inout' do almost the same thing?
>>> The only difference I can see between const and inout, is that inout
>>> tells which parameters could be aliased with the return value.

inout is different in that parameters cannot implicitly cast to inout.   
It's actually on the same level as immutable and mutable.

>>  Except that doesn't inout actually produce multiple versions of the  
>> function,
>
> No. My understanding is that the constness of the return value is  
> determined at the call site, but otherwise, it's as if all 'inout'  
> parameters were const.

This is correct, except for the implicit casting thing mentioned above.

-Steve


More information about the Digitalmars-d mailing list