My api would require calling runtime(constFoo(str)) to get the final result, I wanted to shorten this because the real function names are kind of verbose. To do this I need to somehow wrap the consteval function, but I can't do that since the argument cannot be constexpr, it's also a string literal which requires the its size to be known at compile time.
I'm aware of Pass const expression to consteval function through non-consteval functions but it doesn't really solve my issue because I need the size to be known at compile time.
int runtime(int val) {
std::string foo = "foo"; // some run time operation
return val + 2;
}
template <std::size_t N> consteval int constFoo(const char (&data)[N]) {
// ...
const auto d = data[0];
return N;
}
template <std::size_t N> int outer(const char (&data)[N]) {
int val = constFoo(data); // Call to consteval function 'constFoo<2ULL>' is not a constant expression
return runtime(val);
}
int main() {
auto d = outer("d");
}
Also if this would be somehow possible I'd rather avoid a solution where the literal is passed as a template argument, but as far as I'm aware this is impossible.
outer("d")or can your api even be more simple likeouter_d()? If so it doesn't matter you have to type a little more or less in your (internal) implementation of said API.constFooandruntimefunctions are also a part of the api, it's just that there is a usecase where they don't need to be called at the same time, so I cannot just provideouter.