randomSample does not accept char[]

andrea9940 no at mail.plz
Tue Jan 22 02:42:20 PST 2013


Hi everyone,
can you explain me why this code DOES compile:

/*-------------------------------------------------------*/
import std.range, std.random;
void main()
{
	int[] vowels = ['A', 'E', 'I', 'O', 'U'];
	static assert(isInputRange!(typeof(vowels)));
	auto x = randomSample(vowels, 1);
}
/*-------------------------------------------------------*/

but this DOES NOT:

/*-------------------------------------------------------*/
import std.range, std.random;
void main()
{
	char[] vowels = ['A', 'E', 'I', 'O', 'U'];
	static assert(isInputRange!(typeof(vowels))); //pass
	auto x = randomSample(vowels, 1); //fail
}
/*-------------------------------------------------------*/
main.d(6): Error: template std.random.randomSample(R) if 
(isInputRange!(R)) does not match any function template 
declaration
main.d(6): Error: template std.random.randomSample(R) if 
(isInputRange!(R)) cannot deduce template function from argument 
types !()(char[],int)


More information about the Digitalmars-d mailing list