Why D const is annoying

Walter Bright newshound2 at digitalmars.com
Sat Dec 10 12:25:57 PST 2011


On 12/10/2011 11:03 AM, Mehrdad wrote:
> So how are you supposed to implement opApply on a container (or e.g. here, a
> matrix)? Copy/paste the code for const- and non-const versions?

Internal to a function, inout behaves like 'const'. You won't be able to modify 
the data. Therefore, if there is no inout in the return type, use 'const' in the 
parameter list instead.

The purpose of inout is to transmit the 'constness' of the function argument 
type to the return type, using only one implementation of that function. That 
requires the function to internally regard inout as const.


More information about the Digitalmars-d mailing list