Created
May 14, 2013 01:50
-
-
Save Garciat/5573048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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