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