isRandomAccessRange on static array

Jonathan M Davis jmdavisProg at gmx.com
Mon Apr 9 16:22:46 PDT 2012


On Tuesday, April 10, 2012 00:20:20 Brad Anderson wrote:
> A user in IRC was having difficulty using std.algorithm.sort on a
> static array. It appears to be due to static arrays don't pass
> the isRandomAccessRange constraint.
> 
> static assert(isRandomAccessRange!(uint[5]));
> 
> Results in:
> 
> Error: static assert (isRandomAccessRange!(uint[5u])) is
> false
> 
> Is this a bug or am I missing something?

Static arrays are not ranges:

http://stackoverflow.com/questions/8873265/is-a-static-array-a-forward-range

If you want to pass a static array to a range-based function, you must slice 
it first.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list