Last active
August 29, 2015 14:18
-
-
Save John-Colvin/2df6f4f12bfdadc10237 to your computer and use it in GitHub Desktop.
TypeTupleOf
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.range : isInputRange; | |
import std.array : front, empty, popFront; | |
template TypeTupleOf(TL...) | |
if (TL.length == 1 && isInputRange!(typeof(TL[0]))) | |
{ | |
import std.typetuple : TT = TypeTuple; | |
enum r = TL[0]; | |
static if (r.empty) | |
alias TypeTupleOf = TT!(); | |
else | |
{ | |
enum f = r.front; | |
alias TypeTupleOf = TT!( | |
f, | |
TypeTupleOf!( | |
{ auto tmp = r; tmp.popFront(); return tmp; }() | |
) | |
); | |
} | |
} | |
unittest | |
{ | |
import std.range : iota; | |
foreach (i; TypeTupleOf!(iota(10))) | |
{ | |
pragma(msg, i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment