passing a variadic parameter to randomSample

forkit forkit at gmail.com
Tue Jan 25 09:48:25 UTC 2022


so I'm trying to write (or rather learn how to write) a 'variadic 
template function', that returns just one of its variadic 
parameter, randomly chosen.

But can't get my head around the problem here :-(

.. Error: template `std.random.randomSample` cannot deduce 
function from argument types `

// --

module test;
import std;

string RandomChoice(R...)(R r)
{
     auto rnd = MinstdRand0(42);
     return r.randomSample(1, rnd).to!string;
}

void main()
{
     writeln( RandomChoice("typeA", "typeB", "typeC") );
}

// --


More information about the Digitalmars-d-learn mailing list