"headconst" dynamic arrays?

Marco Leise Marco.Leise at gmx.de
Wed Aug 31 13:26:13 PDT 2011


Am 31.08.2011, 21:44 Uhr, schrieb bearophile <bearophileHUGS at lycos.com>:

> Marco Leise:
>
>> Likewise people sometimes modify the input until they've got what
>> they want. Clamping numbers, prefixing strings or replacing default/null
>> values are use cases.
>
> Think about an in-place sort routine. I give an array to it, and its  
> items get shuffled, but nowhere inside the sort routine I want the array  
> length to change. I'd like the array length to be const, but the array  
> items to be mutable. In Phobos there are other examples of in-pace array  
> functions. A system language offers such freedom too.
>
> Bye,
> bearophile

Yeah I was specifically talking about a warning when you overwrite the  
parameter, not modify it's properties or content. It's probably a good  
idea to keep parameters 'head-const' by convention in every case unless  
they are out parameters.
You want the array to be partially modifiable or - regarding length and  
ptr - head-const so routines meant to work on the content only can be  
forced to do so. But then the next thing I would request is the same for  
other ranges. And ranges can be classes, too. I don't think the concept  
can work out if you want to process all ranges the same way in sorting  
algorithms and the like.


More information about the Digitalmars-d mailing list