c++ - 将可变参数包的每个元素包装在包装器中并存储在 std::tuple 中
问题描述
考虑两个类:
struct A {};
struct B {};
还有一个类:
template<typename... Ts>
struct packed {
using Tuple = std::tuple<Ts...>;
Tuple tpl;
};
和
template<typename T>
struct wrapper {
T t;
};
我想要的不是Tuple = std::tuple<Ts...>
inside ofpacked
而是一个元组,它的每个元素都像using WrappedTuple = std::tuple<wrapper<T0>, wrapper<T1>, ..., wrapper<TN-1>>;
目标是通过一组通用属性来增强每个给定类型。
解决方案
只需wrapper<Ts>
扩展...
. 这会生成一个模板参数包,其中每个元素是wrapper<T>
,T
是包中的每个相应类型Ts
。
using Tuple = std::tuple<wrapper<Ts>...>;
(演示)
推荐阅读
- python - 我可以将 self 设置为被忽略的东西吗?
- c# - 如何使用 .net 在 ms 访问中锁定表
- react-native - 查询领域数据库异步时未定义
- php - 循环遍历对象数组PHP
- vue.js - 除非我打开 Vue 开发工具,否则不会触发计算属性
- c# - 如何在 C# 中使用 linq 读取列表中的列表项?
- mongodb - IDE 在导入 mongodb 存储库时出现错误
- c# - 将 HttpWebRequest 重构为 HttpClient?
- mysql - 如何 LEFT JOIN 超过 2 个表以获取没有记录?
- sqoop - OJDBC 驱动程序中的 Cloudera QuickStart VM Sqoop 错误