Text of the sidecar for one header, one Signature specialization per function, sorted by name.
8{
9 std::vector<const FunctionRequest*> sorted;
10 sorted.reserve(functions.
functions.size());
12 sorted.push_back(&function);
13 }
14 std::ranges::sort(sorted, [](const FunctionRequest* a, const FunctionRequest* b) {
15 return std::tie(a->name, a->expression) < std::tie(b->name, b->expression);
16 });
17
18 std::string out;
19 out += "#pragma once\n\n";
20 out += "#include \"MayaFlux/Transitive/Reflect/Describe.hpp\"\n\n";
21 out += "#ifndef MAYAFLUX_REFLECT_SCAN\n\n";
22 out += "namespace MayaFlux::Reflect::Generated {\n\n";
23 for (const FunctionRequest* function : sorted) {
24 out += "template <>\n";
25 out +=
"struct Signature<" + function->
expression +
"> {\n";
26 out +=
" static constexpr std::string_view name = \"" + function->
name +
"\";\n";
27 out +=
" static constexpr std::size_t required = " + std::to_string(function->
required) +
";\n";
28 out +=
" static constexpr std::array<std::string_view, " + std::to_string(function->
parameters.size())
29 + "> parameters {";
30 for (std::size_t i = 0; i < function->
parameters.size(); ++i) {
31 out += i == 0 ? " " : ", ";
33 }
34 out += function->
parameters.empty() ?
"};\n" :
" };\n";
35 out += "\n template <std::size_t K, typename Values>\n";
36 out += " static decltype(auto) call(Values& values)\n {\n";
37 for (std::size_t count = function->
required; count <= function->parameters.size(); ++count) {
38 out += count == function->
required ?
" if constexpr (K == " :
" } else if constexpr (K == ";
39 out += std::to_string(count) + ") {\n";
40 out +=
" return " + function->
callee +
"(";
41 for (std::size_t i = 0; i < count; ++i) {
42 out += i == 0 ? "" : ", ";
43 out += "std::get<" + std::to_string(i) + ">(values)";
44 }
45 out += ");\n";
46 }
47 out += " } else {\n";
48 out += " static_assert(K != K, \"the sidecar has no call with that many arguments\");\n";
49 out += " }\n";
50 out += " }\n";
51 out += "};\n\n";
52 }
53 out += "}\n\n#endif\n";
54 return out;
55}