Forgot to mention that I also want groupIndex!(A,B) == groupIndex!(B,A) Which I wanted to do by sorting the names. If that requirement wasn't there it would be as simple as: auto groupIndex(Ts...)() { return GroupId!Ts.id; } size_t s_nextIdx=1; struct GroupId(Ts ...) { static size_t id; static this() { id = s_nextIdx++; } }