Created
March 7, 2025 22:29
-
-
Save crazymonkyyy/a7b3295286594c45af975c585a226e22 to your computer and use it in GitHub Desktop.
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
alias seq(T...)=T; | |
template groupby(alias F,A...){ | |
template groupby(int I){ | |
alias groupby=seq!(); | |
static foreach(J,a;A){ | |
static if(F(J)==I){ | |
groupby=seq!(groupby,a); | |
} | |
}} | |
} | |
unittest{ | |
import std; | |
alias foo=groupby!(a=>a%2,int,float,bool,1,2,3,13.37); | |
foo!0.stringof.writeln; | |
foo!1.stringof.writeln; | |
alias bar=groupby!(a=>a/3,int,float,bool,1,2,3,13.37); | |
bar!0.stringof.writeln; | |
bar!1.stringof.writeln; | |
bar!2.stringof.writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment