Skip to content

Instantly share code, notes, and snippets.

@kubo39
Created February 21, 2023 00:53
Show Gist options
  • Save kubo39/f1d245834f13821c2ed00fc6d4893ee7 to your computer and use it in GitHub Desktop.
Save kubo39/f1d245834f13821c2ed00fc6d4893ee7 to your computer and use it in GitHub Desktop.
compile-time fizzbuzz
string f(alias T, Args...)()
{
string s;
static if (T % 3 == 0) s ~= "fizz";
static if (T % 5 == 0) s ~= "buzz";
static if (T % 3 != 0 && T % 5 != 0) s ~= T.stringof;
static if (Args.length > 0) return s ~ "," ~ f!(Args)();
else return s;
}
pragma(msg, f!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment