首页 > 解决方案 > 如何转换 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<>::ArgsTypeBasicDefinition<>::ArgValuesType. 但我想摆脱boost::mpl::vectors 并直接从第一种类型构建第二种类型。有可能达到这样的结果吗?

就像是:

template <typename...Args>
struct BasicDefinition
{
    typedef typename boost::fusion::vector<Args...> ArgsType;
    typedef ?????<ArgsTypes, RemoveRef>::type ArgValuesType;
};

标签: c++boostboost-fusion

解决方案


你可能会使用std::decay_t

template <typename...Args>
struct BasicDefinition
{
    using ArgsType = boost::fusion::vector<Args...>;
    using ArgValuesType = boost::fusion::vector<std::decay_t<Args>...>;
};

推荐阅读