Is this a bug? RandomSample claims it needs input range but actually needs forward range

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 18 19:32:27 PDT 2013


On Wednesday, June 19, 2013 03:56:43 finalpatch wrote:
> in the declaration of RandomSample it only checks for
> isInputRange, but in the implementation it calls the .save()
> method which is only available in forward ranges.
> 
> as a result this code does not compile:
> 
> void main()
> {
> auto a = File("test.d", "r").byLine();
> auto s = randomSample(a,1,5);
> writeln(s);
> }
> 
> Is this a bug or I missed something?

Any function which uses save requires at least a forward range, and if its 
template constraint requires only an input range, then its template constraint 
is wrong. _Any_ function whose template constraint does not actually guarantee 
that anything that passes the constraint will compile with that function is 
buggy.

- Jonathan M Davis


More information about the Digitalmars-d mailing list