Re: randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-08 Thread monarch_dodra
On Monday, 4 March 2013 at 23:55:06 UTC, deed wrote: Meaning sortable ranges are actually a narrow subset of random access ranges? Why aren't the constraints listed in the docs? Are the source files and error messages the only way to get this info? Unless I'm mistaken, this was recently fixed

Re: randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread bearophile
deed: Meaning sortable ranges are actually a narrow subset of random access ranges? The result of a map() is more like an immutable (lazy) array. A const array is a random access range, but you can't mutate it. To sort it you need a mutable random access range :-) Why aren't the constrai

Re: randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread deed
import std.algorithm, std.array, std.range; void main() { int[] data = [2, 0, 1]; auto mapped = data.map!q{a * 10}; alias R = typeof(mapped); pragma(msg, hasSwappableElements!R); pragma(msg, hasAssignableElements!R); pragma(msg, isRandomAccessRange!R); pragma(msg, ha

Re: randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread bearophile
deed: auto mappedThenSorted = mapped.sort(); // Error auto mappedThenSorted = mapped.array.sort(); // Works (and used in examples) What am I missing in the documentation? When you try to sort mapped, the D compiler spits out a error message that shows the complex template co

randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread deed
Why randomAccessRange.array() before calling sort? The std.algorithm.sort doc says: "Sorts a random-access range ..." import std.algorithm, std.array; long[] source = [2, 0, 1]; auto mapped = source.map!("a * 10"); assert (isRandomAccessRange!(typeof(mapped))); // Passes. Implies possibilit