Logical const

Jason House jason.james.house at gmail.com
Thu Dec 2 16:40:56 PST 2010


Don 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.
> > 
> > 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.

Inside a function, inout(T) should be considered a subtype of const(T). Nothing should be convertible to inout.



More information about the Digitalmars-d mailing list