Skip to content

Instantly share code, notes, and snippets.

@Zshazz
Created February 28, 2013 01:00
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 Zshazz/c4da4c3e0099062ab7e5 to your computer and use it in GitHub Desktop.
Save Zshazz/c4da4c3e0099062ab7e5 to your computer and use it in GitHub Desktop.
import std.stdio, std.range, std.typecons, std.algorithm;
void main() {
auto a = iota(5);
auto b = repeat(1).take(3);
auto c = [5,9,30];
auto tup = tuple(a,b,c);
foreach(e; tupWrapper(tup).nWayUnion())
writeln(e);
}
auto tupWrapper(Tup)(Tup tup) {
alias E = ElementType!(Tup.Types[0]);
InputRange!E[] arr;
foreach(T; Tup.Types)
static assert(is(ElementType!T == E));
foreach(ref e; tup)
arr ~= inputRangeObject(e);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment