Idiomatic way to process const/immutable arrays as ranges

Dicebot m.strashun at gmail.com
Mon Feb 11 09:01:53 PST 2013


On Monday, 11 February 2013 at 16:35:22 UTC, Steven Schveighoffer 
wrote:
> in means "const scope".  scope is a no-op, const makes the 
> array const, including the pointer length.
>
> const(T)[] means, the ELEMENTS are const, but the pointer and 
> length can be changed.  This makes it a valid input range.
>
> Since your function is making a copy of the data, this should 
> be fine.
>
> Your explanation is difficult to understand, I'm basically 
> going on what your code does.  If you change "in string[]" to 
> "const(string)[]", the function should compile.

I know all of this. And I need guarantees that initial slice will 
always start at the very same point and will never be consumed by 
any part of this function. Thus, I do not need tail const and in 
is exactly what I want. But I see no reason why I can't copy 
slice pointers to create a new tail const range to consume.

To sum up: I want to maintain full const for parameter 
range/slice but be able to create a tail const range from it 
every time I want to actually consume it. Without copying data 
itself.


More information about the Digitalmars-d-learn mailing list