Created
February 21, 2023 00:53
-
-
Save kubo39/f1d245834f13821c2ed00fc6d4893ee7 to your computer and use it in GitHub Desktop.
compile-time fizzbuzz
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
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