c++ - 如何转换 boost::fusion::vector 的类型?
问题描述
我需要为指定的类型列表定义两种类型:第一种是boost::fusion::vector
这些类型,第二种是类型列表中每种类型的boost::fusion::vector
引用和被删除的位置。const
例如,我有int
和。我需要定义和。unsigned &
long const &
boost::fusion::vector<int, unsigned &, long const &>
boost::fusion::vector<int, unsigned, long>
这是我的代码:
struct RemoveRef
{
template <class T>
struct apply
{
using type =
typename std::remove_const<typename std::remove_reference<T>::type>::type;
};
};
template <typename...Args>
struct BasicDefinition
{
typedef typename boost::mpl::vector<Args...> Types;
typedef typename boost::fusion::result_of::as_vector<Types>::type ArgsType;
typedef typename boost::mpl::transform<Types, RemoveRef>::type ValueTypes;
typedef typename boost::fusion::result_of::as_vector<ValueTypes>::type ArgValuesType;
};
有用。我得到这些类型BasicDefinition<>::ArgsType
和BasicDefinition<>::ArgValuesType
. 但我想摆脱boost::mpl::vector
s 并直接从第一种类型构建第二种类型。有可能达到这样的结果吗?
就像是:
template <typename...Args>
struct BasicDefinition
{
typedef typename boost::fusion::vector<Args...> ArgsType;
typedef ?????<ArgsTypes, RemoveRef>::type ArgValuesType;
};
解决方案
你可能会使用std::decay_t
template <typename...Args>
struct BasicDefinition
{
using ArgsType = boost::fusion::vector<Args...>;
using ArgValuesType = boost::fusion::vector<std::decay_t<Args>...>;
};
推荐阅读
- r - ISO 8061 dmy 在更改日期的某一行后无法解析
- asp.net-mvc - 如何在 ASP.NET API 中实现 PayEx 支付网关?
- python - 对无关窗口的奇怪 sdl 副作用
- php - 是否有任何可能的方法仅将 firebase 数据库用于实时消息传递并将数据存储在自己的服务器上
- xodus - 如何使用 Xodux-DNQ 更新实体
- arrays - 在使用 API 和 ANGULAR 7 选择对象时,我们如何将对象从一个数组移动到另一个数组?
- c++ - 编译时如何禁用部分代码
- node.js - Babel 错误:“错误:无法从 '/vagrant' 找到模块 'babel-plugin-transform-object-rest-spread'”
- batch-file - 有没有办法编写批处理函数来增加注册表的值名称?
- javascript - 通过另一个属性分配属性值并更改属性值