On 04/22/2012 04:19 PM, Joseph Rushton Wakeling wrote:
Is there a way in which to pass a function as input to another function,
with the arguments of the first function already determined?

The case I'm thinking of is one where I have a function which wants to
take a random number generation scheme, and use it on several occasions,
without having any info on that scheme or its parameters.

Here's a little test attempt I made:

////////////////////////////////////////////////////
import std.random, std.range, std.stdio;

void printRandomNumbers(RandomNumberGenerator)(RandomNumberGenerator
rng, size_t n)
{
foreach(i; 0..n)
writeln(rng);

You just need to call the delegate with the function call syntax:

          writeln(rng());

Ali

Reply via email to