Bug 10265 – RandomSample fails when passed an InputRange as input

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-04T06:23:00Z
Last change time
2013-06-08T02:25:29Z
Assigned to
nobody
Creator
joseph.wakeling

Comments

Comment #0 by joseph.wakeling — 2013-06-04T06:23:21Z
By design, RandomSample is supposed to operate on any InputRange: struct RandomSample(R, Random = void) if(isInputRange!R && (isUniformRNG!Random || is(Random == void))) However, RandomSample itself is designed to be a ForwardRange with save() defined. The save property in turn assumes that the input has save() defined: @property typeof(this) save() { auto ret = this; ret._input = _input.save; return ret; } The assumption that RandomSample can have save() defined is also problematic for a second reason: the output from the saved copy will depend on random numbers, and therefore will not be identical, so it is not clear what the benefit of a save() function is.
Comment #1 by joseph.wakeling — 2013-06-04T10:42:05Z
Comment #2 by github-bugzilla — 2013-06-07T12:06:31Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/cbdd14b57b41092d4e75dc11338b14c9d61ebd9e Issue 10265 - RandomSample fails when passed an InputRange as input * Issue fixed by making presence of save() property conditional on input being a ForwardRange. https://github.com/D-Programming-Language/phobos/commit/783902cafb17eed755d185f63ea2bafa63e4f387 Merge pull request #1332 from WebDrake/randomsample-save Issue 10265 - RandomSample fails when passed an InputRange as input