-
-
Save Zshazz/c4da4c3e0099062ab7e5 to your computer and use it in GitHub Desktop.
This file contains 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, 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