Этот пример взят отсюда. class = "lang-cpp prettyprint-override">
Код: Выделить всё
#include
template
using forward_t = decltype(X::forward(std::declval()...));
template
struct Function {
template
static auto apply(Args &&...args) {
using forward_return_t = forward_t;
// Do something with params before calling forward ...
forward_return_t output = T::forward(std::forward(args)...);
return output;
}
};
struct Addition : public Function {
static int forward(int lhs, int rhs) {
return lhs + rhs;
}
};
struct Subtraction : public Function {
static double forward(double lhs, double rhs) {
return lhs - rhs;
}
};
int main() {
auto add_value = Addition::apply(10, 15);
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/76083375/is-a-different-template-parameter-required-for-return-type-deduction-in-crtp[/url]