SortedRange and new docs for std.container
Jesse Phillips
jessekphillips+D at gmail.com
Wed Sep 8 12:47:10 PDT 2010
Andrei Alexandrescu Wrote:
> On 9/8/10 12:06 CDT, Andrej Mitrovic wrote:
> > I don't want to hijack the topic, but can I ask a question?
> >
> > In the Phobos docs I often see this kind of code:
> >
> > assert(equal(radial(a), [ 3, 4, 2, 5, 1 ][]));
> >
> > What is the purpose of the extra square brackets after the array
> > literal? Because the code works both with and without them.
>
> Just historical vestige. There was a time when it didn't work without
> the [].
>
> Andrei
To be more exact, [3,4,2,5,1] use to create a static array, int[5u], but what was required was a dynamic array, int[], by adding the ending [] you are taking a 'slice' of the entire array, which is of type int[]. adding the [] to the end still does the same thing, but now array literals are dynamic arrays. You can use literals to create static arrays by giving the type you want.
http://ideone.com/qInPu
The default was changed because Phobos was littered with [...][] in all the tests... Andrei must have gotten annoyed. :)
More information about the Digitalmars-d
mailing list