| 1 | #include <cstdlib> |
| 2 | #include <iostream> |
| 3 | #include <sstream> |
| 4 | |
| 5 | using namespace std; |
| 6 | |
| 7 | void build_code(int max_args) |
| 8 | { |
| 9 | stringstream ss; |
| 10 | ss << "#define NLOHMANN_JSON_EXPAND( x ) x" << endl; |
| 11 | ss << "#define NLOHMANN_JSON_GET_MACRO("; |
| 12 | for (int i = 0 ; i < max_args ; i++) |
| 13 | ss << "_" << i + 1 << ", "; |
| 14 | ss << "NAME,...) NAME" << endl; |
| 15 | |
| 16 | ss << "#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\" << endl; |
| 17 | for (int i = max_args ; i > 1 ; i--) |
| 18 | ss << "NLOHMANN_JSON_PASTE" << i << ", \\" << endl; |
| 19 | ss << "NLOHMANN_JSON_PASTE1)(__VA_ARGS__))" << endl; |
| 20 | |
| 21 | ss << "#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)" << endl; |
| 22 | for (int i = 3 ; i <= max_args ; i++) |
| 23 | { |
| 24 | ss << "#define NLOHMANN_JSON_PASTE" << i << "(func, "; |
| 25 | for (int j = 1 ; j < i -1 ; j++) |
| 26 | ss << "v" << j << ", "; |
| 27 | ss << "v" << i-1 << ") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE" << i-1 << "(func, "; |
| 28 | for (int j = 2 ; j < i-1 ; j++) |
| 29 | ss << "v" << j << ", "; |
| 30 | ss << "v" << i-1 << ")" << endl; |
| 31 | } |
| 32 | |
| 33 | cout << ss.str() << endl; |
| 34 | } |
| 35 | |
| 36 | int main(int argc, char** argv) |
| 37 | { |
| 38 | int max_args = 64; |
| 39 | build_code(max_args); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 |