Skip to content

Instantly share code, notes, and snippets.

@gcharnock
Created January 18, 2011 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcharnock/783771 to your computer and use it in GitHub Desktop.
Save gcharnock/783771 to your computer and use it in GitHub Desktop.
staticReduce template
import std.typetuple;
template staticReduce(alias F,T...) {
static if(T.length==0) {
alias TypeTuple!() staticReduce;
} else static if(T.length==1) {
enum staticReduce=T[0];
} else {
enum staticReduce=staticReduce!(F,TypeTuple!(F!(T[0],T[1]),T[2..$]));
}
}
//Testing/demos
template concan(string s1,string s2) {enum concan = s1 ~ s2;};
static assert(staticReduce!(concan,"Hello world")=="Hello world");
import std.metastrings;
static assert(staticReduce!(concan,"Hello world"," from ","static reduce! Here is an int:", toStringNow!(5))
=="Hello world from static reduce! Here is an int:5");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment