我有一段代码,其中大量使用了模板。一个例子如下:
template <class MT>
struct class_method_info;
template <class T, class Res, class... Args>
struct class_method_info<Res(T::*)(Args...)>
{
typedef std::tuple<Args&&...> ArgsTuple;
typedef T ClassType;
typedef Res RetVal;
static constexpr std::size_t ArgsCount = sizeof...(Args);
static constexpr bool IsClassMethod = true;
};
这适用于非const成员函数指针。 如果我将
Res(T::*)(Args...)
更改为Res(T::*)(Args...) const
,我可以传递const
函数指针。然而,即使这是一种有效的解决方案,它也会破坏我的代码,因为现在我的所有内容都是成双成对的,并且有很多这样的情况。
是否有其他方法?
std::mem_fn
没有满足你的要求,否则你应该看一下它。 - Arunmu