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