|
1 | 1 | #include "factorial.hpp" |
2 | 2 |
|
| 3 | +#include <%%cpp_init_replace%%/config.hpp> |
3 | 4 | #include <%%cpp_init_replace%%/fib.hpp> |
4 | 5 |
|
5 | | -#include <print> |
| 6 | +#include <cstdlib> |
| 7 | +#if defined(%%CPP_INIT_REPLACE%%_COMPILER_GNU) && %%CPP_INIT_REPLACE%%_COMPILER_VERSION_MAJOR < 14 |
| 8 | +# include <cstdio> |
| 9 | +# include <format> |
| 10 | +# define %%CPP_INIT_REPLACE%%_PRINTLN(fp, ...) \ |
| 11 | + (void)std::fputs(std::format(__VA_ARGS__).c_str(), fp); \ |
| 12 | + (void)std::fputc('\n', fp) |
| 13 | +#else |
| 14 | +# include <print> |
| 15 | +# define %%CPP_INIT_REPLACE%%_PRINTLN(...) std::println(__VA_ARGS__) |
| 16 | +#endif |
6 | 17 | #include <stdexcept> |
7 | 18 | #include <string> |
8 | | -#include <cstdlib> |
9 | 19 |
|
10 | 20 | int main(int argc, char *argv[]) { |
11 | 21 | if (argc != 2) { |
12 | | - std::println(stderr, "Wrong number of arguments, expected 1, got {}", argc - 1); |
| 22 | + %%CPP_INIT_REPLACE%%_PRINTLN(stderr, "Wrong number of arguments, expected 1, got {}", argc - 1); |
13 | 23 | return 1; |
14 | 24 | } |
15 | 25 | auto const num = [arg = argv[1]]() { |
16 | 26 | try { |
17 | 27 | return std::stoll(arg); |
18 | 28 | } catch (std::logic_error const &e) { |
19 | | - std::println(stderr, "Could not parse command line argument: {}", e.what()); |
| 29 | + %%CPP_INIT_REPLACE%%_PRINTLN(stderr, "Could not parse command line argument: {}", e.what()); |
20 | 30 | std::exit(1); // NOLINT(concurrency-mt-unsafe) |
21 | 31 | } |
22 | 32 | }(); |
23 | 33 |
|
24 | | - std::println("{}! = {}", num, %%cpp_init_namespace%%::factorial(num)); |
25 | | - std::println("fib({}) = {}", num, %%cpp_init_namespace%%::fib(num)); |
| 34 | + %%CPP_INIT_REPLACE%%_PRINTLN(stdout, "{}! = {}", num, %%cpp_init_namespace%%::factorial(num)); |
| 35 | + %%CPP_INIT_REPLACE%%_PRINTLN(stdout, "fib({}) = {}", num, %%cpp_init_namespace%%::fib(num)); |
26 | 36 |
|
27 | 37 | return 0; |
28 | 38 | } |
0 commit comments