包含可变模板的元组
Tuple which includes a variadic template
我有以下代码:
template<typename... A>
void queueQuery(std::string query, std::function<void(A...)> callback = nullptr);
template<typename... A>
std::tuple<std::string, std::function<void(A...)> queryCallback;
std::queue<queryCallback> queryQueue;
我想创建一个字符串和函数的元组队列,这些字符串和函数具有任意给定类型的可变数(我理解,这很复杂(。
有没有办法做到这一点?
我目前得到以下错误:
/databasedispatcher.h:14: error: data member 'queryCallback' cannot be a member template
您正在定义queryCallback
template<typename... A>
std::tuple<std::string, std::function<void(A...)> queryCallback;
作为一个变量模板(仅符合C++14(。你确定这就是你想要的吗?
如果你想要严格的C++11合规性,那么把你的变量包装成一个结构,如下所示:
template<typename... A>
struct Foo{
std::tuple<std::string, std::function<void (A...)> > queryCallback;
};
然后将其用作临时中的do_something(Foo<int, double>().queryCallback);
,或者Foo<int, double> foo; do_something(foo.queryCallback);
希望这能有所帮助。
相关文章:
- C++:TypeDef使用元组
- Pybind11:将元组列表从Python传递到C++
- 重载元组索引运算符-C++
- 在C++中,如何通过几种类型从元组中选择多个元素
- boost::包含提升单元的元组的哈希值
- 从可调用可变参数元组中的函数结果创建元组
- 检查元组是否包含特定类型的元素
- 哪种类型特征表明该类型是可分配的?(元组,对)
- 如何返回包含 PyObject* 的 boost::p ython::元组?
- CPP 元编程:包含元组函数
- 如何创建一个 std::tuple,其中包含由索引元组指定的向量中的成员
- 如何初始化非默认可构造不可复制对象的元组
- 从可调用元组的结果创建元组
- 如何确定元组是否包含类型
- c++元编程—创建包含模板化方法的所有变体的元组
- 在c++11中,为包含std::元组的对象键入Erasure
- 将类型转换扩展到可转换类型的对/元组
- 一个普通的可复制的::std::元组类模板可能吗?是否存在实现
- 包含可变模板的元组
- 检查引用元组是否为默认可构造时出错