Skip to content

Instantly share code, notes, and snippets.

@Garciat
Created May 14, 2013 01:50
Show Gist options
  • Save Garciat/5573048 to your computer and use it in GitHub Desktop.
Save Garciat/5573048 to your computer and use it in GitHub Desktop.
import std.traits, std.stdio;
void times(F)(uint n, F func)
if (isSomeFunction!F)
{
immutable ar = arity!func;
foreach (uint i; 0 .. n) {
static if (ar == 0) {
func();
} else static if (ar == 1) {
func(i);
} else {
static assert(false, "invalid callable");
}
}
}
void main() {
10.times((uint i) => writeln("hello #", i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment