作为重载运算符的函数包装器

Wrapper for function as overloaded operator

你能解释一下这个定义是什么意思吗?我将其视为 Task 结构的重载模板函数,它调用带有参数 args 的函数并将返回结果转换为 T 类型。

template <class T>
struct Task
{
    template <typename ...Args>
    void operator()(const Args&... args)
    {
        (*static_cast<const T*>(this))(args...);
    }
};

这样做有什么意义?对我来说,它看起来非常过度组合。

此代码:

(*static_cast<const T*>(this))(args...);

在逻辑上等同于:

const T *ptr = static_cast<const T*>(this);
const T &ref = *ptr;
ref(args...);

我想现在应该清楚该语句的作用了(它并没有像您想象的那样转换函数调用的返回值)