如何使用 typedef 和可变参数模板包装除一个模板参数之外的所有模板参数?
How to wrap all but one template arguments using typedef and variadic templates?
我有一个 class 我用 SWIG 包装的 std::function 代理:
template <class TR = void, class ... Types>
struct GenericFunc : std::function<TR (Types...)> {
GenericFunc() {}
GenericFunc(const std::function<TR (Types... t)> & Action) : std::function<TR (Types... t)>(Action) {}
virtual TR OnAction(Types ... result) {
if(*this) {
return (*this)(result...);
}
return TR();
}
virtual ~GenericFunc(){}
};
在 C# 或 Java 中可以重载 OnAction
并得到他想要的东西,而在 C++ 方面我们只有一个额外的检查。
拥有 Func
的人会喜欢拥有 Action
- 一个 return 无效的功能。
typedef GenericFunc<void, Types...> GenericAction<class ... Types>;
所以我想知道如何使用 typedef(不是继承)创建一个动作。并且 I get many errors
如何通过 C++11 和 typedef 包装某些类型?
您可以使用 alias template.
template<class... Types>
using GenericAction = GenericFunc<void, Types...>;
我有一个 class 我用 SWIG 包装的 std::function 代理:
template <class TR = void, class ... Types>
struct GenericFunc : std::function<TR (Types...)> {
GenericFunc() {}
GenericFunc(const std::function<TR (Types... t)> & Action) : std::function<TR (Types... t)>(Action) {}
virtual TR OnAction(Types ... result) {
if(*this) {
return (*this)(result...);
}
return TR();
}
virtual ~GenericFunc(){}
};
在 C# 或 Java 中可以重载 OnAction
并得到他想要的东西,而在 C++ 方面我们只有一个额外的检查。
拥有 Func
的人会喜欢拥有 Action
- 一个 return 无效的功能。
typedef GenericFunc<void, Types...> GenericAction<class ... Types>;
所以我想知道如何使用 typedef(不是继承)创建一个动作。并且 I get many errors
如何通过 C++11 和 typedef 包装某些类型?
您可以使用 alias template.
template<class... Types>
using GenericAction = GenericFunc<void, Types...>;