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

finalpatch fengli at gmail.com
Tue Jun 18 20:48:13 PDT 2013


On Wednesday, 19 June 2013 at 02:32:46 UTC, Jonathan M Davis 
wrote:
> 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

So you are saying this is a bug in std.random?



More information about the Digitalmars-d mailing list