#include #include #include #include #include #ifdef ASYNC #include #endif using namespace std; string fizzy(int n) { int a = n % 3, b = n % 5; if (a == 0 && b == 0) { return "FizzBuzz"; } else if (a == 0) { return "Fizz"; } else if (b == 0) { return "Buzz"; } else { stringstream out; out << n; return out.str(); } } void fizzbuzz() { vector range(100, 0); #ifdef ASYNC iota(range.begin(), range.end(), 0); #endif vector strings(range.size(), ""); #ifdef ASYNC vector> futures; #endif #ifdef AUTO for (auto i : range) { #elsif int i; for (i = 0; i < range.size(); i++) { #endif #ifdef ASYNC futures.emplace_back( std::async( launch::async, [&]() { #endif strings[i] = fizzy(i + 1); #ifdef ASYNC } ) ); #endif } for (auto s : strings) { cout << s << endl; } } int main() { fizzbuzz(); }