Compiler Explorer
DRANK
void fizzbuzz() { for (int i = 1; i <= 100; ++i) { inspect (std::pair(i%3, i%5)) { [0 , 0 ] => { std::cout << "fizzbuzz\n"; } [0 , __] => { std::cout << "fizz\n"; } [__, 0 ] => { std::cout << "buzz\n"; } [__, __] => { std::cout << i << '\n'; } }; } } int main() { fizzbuzz(); }
1 comments
x86-64 clang (experimental pattern matching)
を選択することで機能が有効に#include <iostream> #include <utility> void fizzbuzz() { for (int i = 1; i <= 100; ++i) { inspect (std::pair(i%3, i%5)) { [0 , 0 ] => { std::cout << "fizzbuzz\n"; } [0 , __] => { std::cout << "fizz\n"; } [__, 0 ] => { std::cout << "buzz\n"; } [__, __] => { std::cout << i << '\n'; } }; } } int main() { fizzbuzz(); }