FizzBuzz: Difference between revisions
Content deleted Content added
Line 1,701:
=={{header|C++}}==
===minimal conditions===
<
#include <chrono>
Line 1,740:
return 0;
}
</syntaxhighlight>
===with modulo===
<
using namespace std;
Line 1,759:
}
return 0;
}</
===without modulo 15===
<
using namespace std;
Line 1,779:
}
return 0;
}</
===without modulo===
Modulo can be expensive on some architectures.
<
int main()
Line 1,798:
return 0;
}
</syntaxhighlight>
===using std::transform===
{{works with|C++11}}
<
#include <algorithm>
#include <vector>
Line 1,825:
return 0;
}</
===metaprogramming===
Version computing FizzBuzz at compile time with metaprogramming:
<
template <int n, int m3, int m5>
Line 1,875:
fb_run<100> fb;
return 0;
}</
===hardcore templates===
Compile with -ftemplate-depth-9000 -std=c++0x:
<
#include <string>
#include <cstdlib>
Line 2,041:
std::cout << mpl::c_str<FizzBuzz<n>::type>::value << std::endl;
return 0;
}</
Note: it takes up lots of memory and takes several seconds to compile. To enable compilation for 7 < n <= 25, please, modify include/boost/mpl/limits/string.hpp BOOST_MPL_LIMIT_STRING_SIZE to 128 instead of 32).
|