我需要为指定的类型列表定义两种类型:第一种是 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>...>;
};
关于c++ - 如何转换boost::fusion::vector的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707046/