why does phobos use [0, 5, 8, 9][] instead of [0, 5, 8, 9] in examples?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 7 22:53:41 PDT 2015


On 04/07/2015 07:40 PM, Timothee Cour via Digitalmars-d-learn wrote:
> Eg, code like this in std.algorithm:
> assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9][]));
> why not just:
> assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9]));
> ?
>

It must be a leftover from the time when the type of an array literal 
was a static array (versus a dynamic one). Since static arrays are not 
ranges, the author of the code apparently has first created a slice to 
its elements.

However, today array literals are already slices.

Ali



More information about the Digitalmars-d-learn mailing list