Skip to content

Instantly share code, notes, and snippets.

@John-Colvin
Last active August 29, 2015 14:18
Show Gist options
  • Save John-Colvin/2df6f4f12bfdadc10237 to your computer and use it in GitHub Desktop.
Save John-Colvin/2df6f4f12bfdadc10237 to your computer and use it in GitHub Desktop.
TypeTupleOf
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