Idiomatic way to process const/immutable arrays as ranges

Dicebot m.strashun at gmail.com
Mon Feb 11 07:28:28 PST 2013


On Monday, 11 February 2013 at 14:53:17 UTC, Namespace wrote:
> On Monday, 11 February 2013 at 14:46:55 UTC, Dicebot wrote:
>> This question is so stupid I am just struck with trying to 
>> chose the "good" solution.
>>
>> Consider this code:
>>
>> string func(in string[] args)
>> {
>>    return args.join(" "); // compile error, args is not an 
>> input range
>> }
>>
>> It is somewhat expected as you can hardly popFront on a const 
>> range. But then question is: how can I wrap const slice into a 
>> mutable range without copying data (using standard 
>> language/library solution)? Of course, I can do .dup.join, but 
>> there is no real need to do copy, even a shallow one.
>
> Try:
> string func(string[] args)
> without 'in'.

I have "in" there for a reason. There is no rationale in removing 
it. My request is perfectly valid - creating a mutable range for 
immutable array traversal.


More information about the Digitalmars-d-learn mailing list