Last active
January 4, 2016 15:05
-
-
Save alphaKAI/caea803d7011f14ca98a to your computer and use it in GitHub Desktop.
D言語でTemplate Meta Programmingを駆使して書いた、任意の深さのnested forを生成するテンプレート
This file contains hidden or 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.stdio; | |
template FOR(alias func, alias cond) { | |
import std.algorithm, | |
std.traits, | |
std.range, | |
std.conv; | |
void FOR() { | |
immutable lambdaStr = (lamArgs => | |
(temp) { | |
foreach(e; lamArgs) { | |
temp ~= "for(ulong " ~ e ~ "; " ~ "cond(" ~ e ~ "); " ~ e ~ "++)"; | |
} | |
return temp ~ "func(" ~ lamArgs.join(", ") ~ ");"; | |
}("") | |
)(arity!func.iota.map!(i => "arg" ~ i.to!string)); | |
mixin(lambdaStr); | |
} | |
} | |
void main() { | |
FOR!((ulong i1, ulong i2) => writeln(i1 * i2), i => i < 4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment