Working with ranges

Murilo murilomiranda92 at hotmail.com
Sat Dec 8 04:57:05 UTC 2018


On Saturday, 8 December 2018 at 04:16:25 UTC, Adam D. Ruppe wrote:
> On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote:
>> What is the difference between declaring "int[3] a = [1,2,3];" 
>> and declaring "int[] a = [1,2,3];"? Is the first an array and 
>> the second a range?
>
> They are both arrays, just the former one has a fixed size and 
> the latter does not. Ranges require a way to iterate and 
> consume elements, meaning they cannot be fixed size.
>
>> I always thought that leaving the square brackets empty would 
>> create an array of flexible size, it never occurred to me that 
>> it was creating something else.
>
> That's what it is, just a flexible array also happens to be an 
> array, whereas a fixed-size array is not one.
>
> But a slice of a fixed size one yields a flexible one.. which 
> is why the ps[] thing works to create a range out of it.

Thank you guys so much for the explanation, it is all making more 
sense now.


More information about the Digitalmars-d-learn mailing list